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.

SAS Innovate 2025: Register Now

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!

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
  • 1031 views
  • 2 likes
  • 4 in conversation