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);
you need to turn in 'on' in SAS for macros:
options minoperator;
See this SAS Note:
Thank you Reeza,
very impressive solution (I will try it later,) but I use SAS9.1 which not support this nice option .
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;
Awesome!
thank you Tom,
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.