我在EIS列中有一个日期函数(例如:05FEB 2007),我想循环从31 DEC2012到31 DEC2022的年份,但必须像31 DEC2012-EIS最多循环31 DEC2022-EIS。
%MACRO NFORE;
%LET UC=100;
%LET YS=2012;
%DO I = 0 %TO 10;
%LET YRS=%EVAL(&YS+&I);
proc sql;
create table FORECAST_&YRS as
select t.*,
case when (31DEC&YRS-EIS)/365<=10 then Segment_10
when (31DEC&YRS-EIS)/365<=20 then Segment_20
when (31DEC&YRS-EIS)/365<=30 then Segment_30
when (31DEC&YRS-EIS)/365<=99 then Segment_35
else stat
end as TSN_AGE_&YRS
from F_AG t;
quit;
%END;
%MEND NFORE;
%NFORE;发布于 2013-09-25 15:41:38
我将用我的标准作为开头,“这是个坏主意,有一个比在宏循环中生成大量数据集更好的方法(您的问题)”,但这是这么说的:
%MACRO NFORE;
%LET UC=100;
%LET YS=2012;
%DO yrs= &ys. %TO %eval(&ys.+10);
proc sql;
create table FORECAST_&YRS as
select *
,case when ("31DEC&YRS."d-EIS)/365<=10 then Segment_10
when ("31DEC&YRS."d-EIS)/365<=20 then Segment_20
when ("31DEC&YRS."d-EIS)/365<=30 then Segment_30
when ("31DEC&YRS."d-EIS)/365<=99 then Segment_35
else stat end as TSN_AGE_&YRS
from F_AG;
quit;
%END;
%MEND NFORE;
%NFORE;在计算实际年份方面,一个稍微优越的解决方案是使用INTCK函数来确定日期之间的年份,这将处理闰年,甚至在EIS上使用YEAR函数,只需比较&yrs。到年份(EIS),因为您使用的是DEC 31。
https://stackoverflow.com/questions/19009131
复制相似问题