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

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

1 ACCEPTED SOLUTION

Accepted Solutions
ed_sas_member
Meteorite | Level 14

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)

View solution in original post

5 REPLIES 5
ed_sas_member
Meteorite | Level 14

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)
Jens89
Obsidian | Level 7

that's beautiful! thanks 

novinosrin
Tourmaline | Level 20

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))

 

ballardw
Super User

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: 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!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 5 replies
  • 921 views
  • 1 like
  • 4 in conversation