比较日期
问题描述:
我想通过比较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 ='2014年8月31日' - 显然可以看出比较的结果是错误的?
答
您的日期比较中没有“怪异行为”,这是正确的。这个问题是,你混的宏观和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.) ;
一个完美的解释和解决方案! – kaytrance 2014-09-04 10:59:26