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

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???***/

 
1 ACCEPTED SOLUTION

Accepted Solutions
ErikLund_Jensen
Rhodochrosite | Level 12

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

View solution in original post

7 REPLIES 7
ErikLund_Jensen
Rhodochrosite | Level 12

Hi @Ronein 

 

A macro doesn't accet the IN-operator unless it is specified with the macro definition:

%macro macroname(parm) / minoperator;

 

Ronein
Meteorite | Level 14
But IF there is one element then the IN is working(%RRR(4) is working well)
ErikLund_Jensen
Rhodochrosite | Level 12

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));
Ronein
Meteorite | Level 14

MAy you please show the full code? I would like to test it via sas

Ronein
Meteorite | Level 14

With comma it works well

Tom
Super User Tom
Super User

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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1573 views
  • 2 likes
  • 4 in conversation