BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jwdenham
Fluorite | Level 6

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;

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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;

 

 

--
Paige Miller

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

In data set TRACKER3, look at the values of variables name and email. Are there commas in these variables?

--
Paige Miller
jwdenham
Fluorite | Level 6

Yes, the values in the name variable are in this format: Last, First

PaigeMiller
Diamond | Level 26

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;

 

 

--
Paige Miller
jwdenham
Fluorite | Level 6

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.

PaigeMiller
Diamond | Level 26

Show me a few lines of code generated by CALL EXECUTE as it appears in the LOG (and any error messages as well)

--
Paige Miller
jwdenham
Fluorite | Level 6

I closed/reopened the mail client and re-ran the code. It all works perfectly. Thank you very much for your help.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 907 views
  • 1 like
  • 2 in conversation