比较日期时的奇怪行为

时间:2014-09-04 09:58:11

标签: sas

我想通过以下方式比较2个日期常量:

data _null_;
    %put checking if &period_bop1Yend is greater than &latest_date;
    if "&period_bop1Yend"d > "&latest_date"d then do;
        %put "IF entered";
        %let period_bop1Yend = &latest_date;
    end;
run;
%put &period_bop1Yend;

但是当& period_bop1Yend ='31DEC2013'和& latest_date ='31AUG2014'时,为什么我会在日志中收到“IF输入”消息 - 很明显比较的结果是假的???

1 个答案:

答案 0 :(得分:4)

没有奇怪的行为'在你的日期比较中,它是正确的。这个问题是你错误地混合宏和datastep ...

data _null_;
    put "checking if &period_bop1Yend is greater than &latest_date" ;
    if "&period_bop1Yend"d > "&latest_date"d then do;
        put "IF entered";
        call symput('period_bop1Yend',"&latest_date"d) ;
    end;
run;
%put &period_bop1Yend;

但为什么不这样做更简单......

%LET PERIOD_BOP1YEND = %SYSFUNC(max("&PERIOD_BOP1YEND"d,"&LATEST_DATE"d),date9.) ;
相关问题