BookmarkSubscribeRSS Feed
Mike_Davis
Fluorite | Level 6

Hello everyone,

I want to use an alternative method to simplify "%if (&a=1 or &a=2 or &a=3)" in macro  %test  in the SAS code below

The %test macro works but the %test2 will cause error, the error parts caused by "%if &a in (1,2,3) %then....."

Please advise.

Thanks!

Mike

%macro test(a);
%if (&a=1 or &a=2 or &a=3) %then %do;%put a=1/2/3;%end;
%else %do;%put a=other;%end;
%mend test;

%test(a=2);
%test(a=5);

%macro test2(a);
%if &a in (1,2,3) %then %do;%put a=1/2/3;%end;
%else %do;%put a=other;%end;
%mend test2;

%test2(a=2);
%test2(a=5);

4 REPLIES 4
Reeza
Super User

you need to turn in 'on' in SAS for macros:

options minoperator;

See this SAS Note:

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

Mike_Davis
Fluorite | Level 6

Thank you Reeza,

very impressive solution (I will try it later,)  but I use SAS9.1 which  not support this nice option .


Tom
Super User Tom
Super User

I find that using indexw is just as easy and compatible with older versions of SAS.

%if %sysfunc(indexw(1 2 3,&a)) %then %put a=1/2/3;

%else %put a=other;

Mike_Davis
Fluorite | Level 6

Awesome!


thank you Tom,

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 1080 views
  • 4 likes
  • 3 in conversation