如何在宏语言的%if语句中使用in逻辑语句【转载】
This example turns on the MINOPERATOR system option to make the IN operator available. The MINDELIMITER= %MACRO statement option to change the delimiter from a space to a comma. The MLOGIC system option is also turned on to show how the %IF condition is evaluated.
options minoperator mlogic;
%macro test(value)/mindelimiter=',';
%if &value in 1,2,3,4,5,6 %then
%put Value found within list.;
%else %put Value not in list.;
%mend;
%test(3)
/*Prior to SAS9.2, the following syntax was used*/
%macro test(value);
%if &value=1 or &value=2 or &value=3 or &value=4 or
&value=5 or &value=6 %then %put Value found within list.;
%else %put Value not in list.;
%mend;
%test(3)
OUTPUT:
43 options minoperator mlogic;;
44 %macro test(value)/mindelimiter=','; By default: mindelimiter = “space”;
45
46 %if &value in 1,2,3,4,5,6 %then
47 %put Value found within list.;
48 %else %put Value not in list.;
49
50 %mend;
51
52 %test(3)
MLOGIC(TEST): Beginning execution.
MLOGIC(TEST): Parameter VALUE has value 3
MLOGIC(TEST): %IF condition &value in 1,2,3,4,5,6 is TRUE
MLOGIC(TEST): %PUT Value found within list.
Value found within list.
MLOGIC(TEST): Ending execution.