I'm looking to enter a list of values as a parameter in a macro.
eg:
%macro test(list_of_values);
data analysis;
set file;
where numbers in (&list_of_values);
run;
%mend;
So then I can enter something like
%test((100,101,102))it's not always 3 numbers, it could also be 2 or 4. the list of values is also not the only parameter. I have some more in my code but the list would be one of them
Hi @Jens89
You can replace commas by spaces in the in operator parenthesis.
I have added the input dataset as another parameter to show you how to write the code :
%macro test(list_of_values,dataset); data analysis; set &dataset; where numbers in (&list_of_values); run; %mend; %test(100 101 102, file)
You can also use the %str function if you want to mask commas:
%test(%str(100 101 102),file)
Hi @Jens89
You can replace commas by spaces in the in operator parenthesis.
I have added the input dataset as another parameter to show you how to write the code :
%macro test(list_of_values,dataset); data analysis; set &dataset; where numbers in (&list_of_values); run; %mend; %test(100 101 102, file)
You can also use the %str function if you want to mask commas:
%test(%str(100 101 102),file)
that's beautiful! thanks
Thank you @Jens89 !
Hi @Jens89 just quote the values to make the macro processor treat the commas as text rather than a separator of positional parameters or use keyword parameters with =
For example
%test(%bquote(100,101,102))
%test(list_of_values=100,101,102))
If you are going to do such things frequently you may want to investigate the macro option PARMBUFF as well.
My online help even shows the PARMBUFF used with a comma delimited list.
If you use PARMBUFF with other parameters the PARMBUFF values must be the last parameter passed.
You will likely still need to parse/loop over the values for some uses.
You might try:
%macro test /parmbuff;
data analysis;
set file;
where numbers in &syspbuff.;
run;
%mend;
%test (100, 101, 102)
Note that the () are part of the parameter used this way. Also the Parmbuff option populates a special macro variable SYSPBUFF.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.