sas macro1

Reply
Contributor
Posts: 59

sas macro1

[ Edited ]


%macro ab(x);

proc print data=test1 ;where rating in(&x);run;

%mend;
%ab(2,3,4)

 

here i'm getting error that more positional parameters found but if i write

proc print data=test1 ;where rating in(2,3,4);run;

i'm getting the desired output.

 

&x also doing the same then y error is cmng?

I think after resolving macro variable to (2,3,4) it should work like a normal sas program.

.

Please explain how the macro processor is processing these values.

 

 

Esteemed Advisor
Posts: 5,198

Re: sas macro1

The commas between the values make the macro compiler treat them as separate parameters.
In your case the simplest is to skip the commas since IN () can handle blanks as a list separator.
Data never sleeps
Contributor
Posts: 59

Re: sas macro1

if i write 

proc print data=test;

where rating in (2,3,4);run;

i get the desired output.

But instead of 2,3,4 if i write a macro variable which has the sam values(2,3,4) then it is not showing the desired result??

 

macro resolving to 2,3,4 only.so it should print the observations.

Super User
Posts: 1,117

Re: sas macro1

Hope you tried %ab(%str(2,3,4))
Thanks,
Jag
Super User
Posts: 1,117

Re: sas macro1

Please mask the commas using the %str while compilation and you could avoid the error. Try calling the macro as below

%ab(%str(2,3,4))
Thanks,
Jag
Ask a Question
Discussion stats
  • 4 replies
  • 311 views
  • 0 likes
  • 3 in conversation