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-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!

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.

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