Hello
What is the way to define a macro parameter that can get a list of values?
%macro RRR(nr_Cylinders);
Data wanted;
Set SASHELP.CARS;
Where Cylinders in (&nr_Cylinders.);
Run;
%mend;
%RRR(4)
%RRR(4,5) /**Here get an error. Question: How to define a macro parameter that can get a list of values???***/
Hi @Ronein
Sorry, you are right. As you are not using the IN operator in macro code, but in a data step inside the macro, the options is unnecessary, though is does no harm.
A single parameter with two elements can be passed to the macro by separating the values with a blank, while a comma is used to separate two different parameters to the macro. It is also possible to quote a parameter, so it can contain a comma, so all these are valid:
%macro RRR(nr_Cylinders);
Data wanted;
Set SASHELP.CARS;
Where Cylinders in (&nr_Cylinders.);
Run;
%mend;
%RRR(4);
%RRR(4 5);
%RRR(%quote(4,5));
Hi @Ronein
A macro doesn't accet the IN-operator unless it is specified with the macro definition:
%macro macroname(parm) / minoperator;
Hi @Ronein
Sorry, you are right. As you are not using the IN operator in macro code, but in a data step inside the macro, the options is unnecessary, though is does no harm.
A single parameter with two elements can be passed to the macro by separating the values with a blank, while a comma is used to separate two different parameters to the macro. It is also possible to quote a parameter, so it can contain a comma, so all these are valid:
%macro RRR(nr_Cylinders);
Data wanted;
Set SASHELP.CARS;
Where Cylinders in (&nr_Cylinders.);
Run;
%mend;
%RRR(4);
%RRR(4 5);
%RRR(%quote(4,5));
MAy you please show the full code? I would like to test it via sas
What happens when you call the macro like this:
%RRR(4 5)
With comma it works well
Just don't add the comma. The comma tells the macro language you are passing values for two parameters.
The IN operator does not care whether you use spaces or commas between the values.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.