评估逻辑表达式错误的SAS

时间:2018-02-07 15:57:15

标签: sas

我正在试图运行下一个宏,我希望表达"& minimum_age le& age le& maximum_age"取一个假值,因此日志输出应为:"在所需年龄"下,但评估值为true。我真的不明白。

%let date_of_birth = '11may2008'd;
%let minimum_age = 18;
%let maximum_age = 72;
%let age = %sysfunc(int(%sysfunc(yrdif(&date_of_birth,%sysfunc(today()),'AGE'))));
%put &= &age;

%Macro test;
%if not(&minimum_age le &age le &maximum_age) %then %put Under the required age;
%Mend;
%test;

1 个答案:

答案 0 :(得分:2)

评估:

&minimum_age le &age评估为“0”

然后

0 le &maximum_age评估为1

所以not(1) = 0

最后,%put Under the required age未执行

更改为:

%let date_of_birth = '11may2008'd;
%let minimum_age = 18;
%let maximum_age = 72;
%let age = %sysfunc(int(%sysfunc(yrdif(&date_of_birth,%sysfunc(today()),'AGE'))));
%put &= &age;

%Macro test;
%put %eval(&minimum_age ge &age);
%put %eval(&age ge &maximum_age);
%if &minimum_age ge &age or &age ge &maximum_age %then %put Under or up to the required age;
%Mend;
%test;