'in' operator after %if in macro

Accepted Solution Solved
Reply
Contributor
Posts: 36
Accepted Solution

'in' operator after %if in macro

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;


Accepted Solutions
Solution
‎03-06-2015 02:34 PM
Respected Advisor
Posts: 3,124

Re: 'in' operator after %if in macro

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


All Replies
Contributor
Posts: 36

Re: 'in' operator after %if in macro

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.


Solution
‎03-06-2015 02:34 PM
Respected Advisor
Posts: 3,124

Re: 'in' operator after %if in macro

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)

Contributor
Posts: 36

Re: 'in' operator after %if in macro

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

Occasional Contributor
Posts: 12

Re: 'in' operator after %if in macro

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;

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 841 views
  • 0 likes
  • 3 in conversation