Search code examples
sassas-macro

sas passing quoted strings to a macro


so I have a dataset whose elements are strings of emails in quotes. A single data element might look like this: "john@cool.com" "jacob@cool.com" "jingleheimer@cool.com" "smith@cool.com"

I have the following macro command and data step:

%macro Emailer(RCP=);
/* body of the e-mail*/
data _null_;
    file tmp;
    put "Hello, World! <BR>";
run;

/*to-from*/
Filename tmp Email
Subject="Hello World Test"
To= (&RCP)
CT= "text/html";
%mend Emailer;

data _null_;
    set EmailLists;
    call execute('%Emailer(RCP='||ListOfEmails||')');
run;

But I keep getting "ERROR: Macro parameter contains syntax error."

Is it because my data elements have spaces or quotation marks or both?

Thanks in advance.


Solution

  • One way to test it is to pass the parameters directly, rather than with a data step. First I'll rearrange the order of the statements, as commenters pointed out.

    %macro Emailer(RCP=);
      filename myEmail Email;
      data _null_;
        file myEmail Subject = "Hello World Test"
                     To = (&RCP)
                     CT = "text/html";
        put "Hello, World! <BR>";
      run;
      filename myEmail clear;
    %mend Emailer;
    

    And try making any of those work (can't make my 64-bit SAS work with my 32-bits Outlook so I can't test any of this):

    %Emailer(RCP="john@cool.com" "jacob@cool.com" "jingleheimer@cool.com")
    %Emailer(RCP="john@cool.com jacob@cool.com jingleheimer@cool.com")
    %Emailer(RCP=john@cool.com jacob@cool.com jingleheimer@cool.com)
    %Emailer(RCP=john@cool.com ; jacob@cool.com ; jingleheimer@cool.com)
    

    After you figure out which form works, the rest should be easy.