在宏里,用 EQ 和 NE 可以对宏参数本身的值进行判断。通常写作:

%If &var eq %then ...

%If &var ne %then ...

 

EQ:  is checking to see if the macro variable var contains a null value.

NE:  is checking to see if the macro variable var is not equal to a null value. It retruns Ture when &var is resolve to something and returns False when &var does not resolve to anything. 换句话说,当 &var 被赋值时,&var ne would be ture. 当 &var 没有被赋予任何值时,&var ne would be false. 

例子:

%macro mc(year= month= );
    %if &year ne %then x=1;       
    %if &month ne %then y=1;    
%mend;

data test;
%mc(year=2020 month=); /*return x=1 and y=.*/
run;

这里 year 被解析成 2020, month 被没有被解析成任何值,因此第一条 ne 返回 true, 第二条 ne 返回 false. 注意这里宏变量 month=. 和 month= 不一样,前者会被解析成一个空值(而不是 null)并且ne返回true. 

 

posted on 2022-10-18 17:17  MOZY  阅读(95)  评论(0编辑  收藏  举报