macros

Reply
Contributor
Posts: 62

macros


data t;
input name$ rev id;
cards;
a 11121 123
b 32322 223
c 2323 345
;run;

 


%macro a(id);
%put &id;
proc sql;
select storename,storerev,storeid from t where storeid in(&id);


%mend;
%a(123,223);

 

getting error and %put is not printing anything in log?

 

ERROR: More positional parameters found than defined.

plz explain

Respected Advisor
Posts: 3,156

Re: macros

Simply put: You have a comma that needs to be quoted. The Macro quoting is a huge topic, so please do RTM.

 


data t;
input name$ rev id;
cards;
a 11121 123
b 32322 223
c 2323 345
;run;

 


%macro a(id);
%put &id;
proc sql;
select * from t where id in(&id);


%mend;
%a(%str(123,223));
Super User
Posts: 11,343

Re: macros

In more ugly detail: The default delimter between macro variables is a comma. When you used %a(123,223); you told the macro compiler that the value for parameter ID was 123 and then went on to provide the value, 223, for a different parameter but you did not define a second parameter.

 

Note that as of SAS 9.2 you do not need to delimit values when using IN comparisons in datastep or SQL. So %a( 123 223); should work.

 

If you need the list to have commas for another purpose then other approaches will be needed.

Ask a Question
Discussion stats
  • 2 replies
  • 323 views
  • 1 like
  • 3 in conversation