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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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