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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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