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

Hi,

Can I use 'in' operator in macros? It seems the following code doesn't work. Thanks.

%macro test(a);

%if %upcase(&a.) in (A, B, C) %then %let name = Mike;

%mend test;

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

What SAS/EG version you have? It works for me on both SAS 9.3/9.4 with EG 5.1

On my test, it works even when parenthesis is present:

%macro test(a) /minoperator;

%if %upcase(&a) in (A B C) %then %put Hello;

%mend test;

%test(a)

View solution in original post

4 REPLIES 4
swimmer
Calcite | Level 5

Well, I tried this in PC SAS and it worked.

%macro test(a) /minoperator;

%if %upcase(&a) in A B C %then %put Hello;

%mend test;

%test(a);

However, it doesn't work in SAS EG. Any other suggestion? Do I have to write them by ' xxx  or xxx or xxx'? Thanks.


Haikuo
Onyx | Level 15

What SAS/EG version you have? It works for me on both SAS 9.3/9.4 with EG 5.1

On my test, it works even when parenthesis is present:

%macro test(a) /minoperator;

%if %upcase(&a) in (A B C) %then %put Hello;

%mend test;

%test(a)

swimmer
Calcite | Level 5

It worked for me now. I probably did something wrong with the minoperator option. After I restart the SAS EG, it worked! Thanks.

SASMike
Obsidian | Level 7

Here's a reference article I found handy for working with the in operator in macros.  It entails listing the 'in' delimiter.

Hope this helps! Smiley Happy

Sample 35591: How to use the new macro IN operator for SAS 9.2

http://support.sas.com/kb/35/591.html

Starting SAS 9.2, there is an IN operator for the macro language. The IN operator can now be used on the %IF statement when the MINOPERATOR option is set on the %MACRO statement or as a SAS system option.

options minoperator mlogic;

%macro test(value)/mindelimiter=',';

%if &value in 1,2,3,4,5,6 %then

  %put Value found within list.;

%else %put Value not in list.;

%mend;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 35469 views
  • 1 like
  • 3 in conversation