我之前已经发布了类似的循环问题。
在这里,我必须循环 2011 年到 2022 年,但是对于 2011 年,计算与 2012 年到 2022 年不同。从 2012 年开始,cost_2012 取决于 cost_2011,cost_2013 取决于 2012 年的成本。我尝试使用此代码,但我得到了错误消息。
%MACRO NFORE1;
proc sql;
create table cost_news_&time as
select *
,case (31DEC2011.d-EIS)/365<=10 then Segment_0_10
(31DEC2011.d-EIS)/365<=20 then Segment_10_20
else note end as cost_AGE_2011
,Latest_cost+('31DEC2011'd-Latest_cost_Date)/30.44*cost_AGE_2011 as cost_2011
%DO TIME=2012 %TO 2022;
%LET ltime=%eval(&time-1);
,case
("31DEC&time."d-EIS)/365<=10 then Segment_0_10
("31DEC&time."d-EIS)/365<=20 then Segment_10_20
else note end as cost_AGE_&time
,case
calculated cost_<ime + calculated cost_AGE_&time * 12 as cost_&time
from cost_news
;
quit;
%END;
%MEND NFORE1;
%NFORE1;