Help using Base SAS procedures

Problem of using in statement for macro

Reply
Regular Contributor
Posts: 222

Problem of using in statement for macro

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);

Super User
Posts: 19,789

Re: Problem of using in statement for macro

Posted in reply to Mike_Davis

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

options minoperator;

See this SAS Note:

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

Regular Contributor
Posts: 222

Re: Problem of using in statement for macro

Thank you Reeza,

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


Super User
Super User
Posts: 7,039

Re: Problem of using in statement for macro

Posted in reply to Mike_Davis

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;

Regular Contributor
Posts: 222

Re: Problem of using in statement for macro

Awesome!


thank you Tom,

Ask a Question
Discussion stats
  • 4 replies
  • 209 views
  • 4 likes
  • 3 in conversation