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.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.