0

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.

Jesse_m_m
  • 185
  • 1
  • 9
  • Your macro looks upside down. You are writing to the file TMP before you define it with the FILENAME statement. – Tom Jun 15 '16 at 21:50
  • Can I invoke the data step immediately after the FILENAME statement? – Jesse_m_m Jun 15 '16 at 21:55
  • You can reference the fileref defined by the FILENAME statement any time after it is defined. You should post clearer examples of what the input dataset EMAILLISTS has in it. Does it have multiple records or just a single record? – Tom Jun 15 '16 at 23:47
  • Agree with @Tom - can you also paste the log where the error pops up? – Altons Jun 16 '16 at 07:47

1 Answers1

1

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.

Dominic Comtois
  • 10,230
  • 1
  • 39
  • 61
  • Great answer! For your own purposes if it ever comes up, the correct form is this: %Emailer(RCP="john@cool.com""jacob@cool.com""jingleheimer@cool.com") with no spaces. – Jesse_m_m Jun 16 '16 at 13:55
  • Interesting... Just by curiosity, have you tried something like this? `%Emailer(RCP="john@cool.com;jacob@cool.com;jingleheimer@cool.com")` ? – Dominic Comtois Jun 17 '16 at 04:32