Hello all, I was hoping to find some help regarding this macro. I am using it to generate emails to clients based on the values selected by the if statement. I plan to scale this up with more variables (i.e. tracking IDs, etc.) once I have it working, however I am receiving the error:
ERROR: More positional parameters found than defined.
I am having trouble identifying the cause, and I am sure this would be a simple resolution for someone with more experience utilizing macros. I used the paper SAS3212-2019 in helping build it, and reviewed many other issues on these forums that were similar but not quite the same, however I attempted their resolutions with no avail. Any help would be very much appreciated. Thank you
Code:
%macro sendreports(name,email);
filename outbox EMAIL;
data _null_;
FILE outbox
to=("email@mail.com")
from=("email2@mail.com")
sender="email2@mail.com"
subject="Welcome &primaryemail.";
file outbox;
put "Message &name.";put ;
run;
%mend sendreports;
proc sort data=tracker out=tracker2;
by ID Action;
run;
data _null_;
set tracker3;
by ID Action;
if Action in ('1,2');
if first.ID then do;
call execute(cats('%sendreports(',name,',',email,')'));
end;
run;
That's the reason for the error. A comma signals the end of a "positional parameter" and so that comma in the name makes it appear as if you have assigned three positional parameters to a macro that has only two positional parameters.
Try this:
data _null_;
length name $ 64;
set tracker3;
by ID Action;
if Action in ('1,2');
name=tranwrd(name,',','%str(,)');
if first.ID then do;
call execute(cats('%sendreports(',name,',',email,')'));
end;
run;
In data set TRACKER3, look at the values of variables name and email. Are there commas in these variables?
Yes, the values in the name variable are in this format: Last, First
That's the reason for the error. A comma signals the end of a "positional parameter" and so that comma in the name makes it appear as if you have assigned three positional parameters to a macro that has only two positional parameters.
Try this:
data _null_;
length name $ 64;
set tracker3;
by ID Action;
if Action in ('1,2');
name=tranwrd(name,',','%str(,)');
if first.ID then do;
call execute(cats('%sendreports(',name,',',email,')'));
end;
run;
This does allow the macro to process without error for only the name, however it seems to mask the second variable "email" and ignores it upon being sent. Cleaning up the name column does allow it to process once the "," is removed, though it would be ideal to use the method you provided if it didn't ignore the email variable in the process.
Show me a few lines of code generated by CALL EXECUTE as it appears in the LOG (and any error messages as well)
I closed/reopened the mail client and re-ran the code. It all works perfectly. Thank you very much for your help.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.