我想通过使用条件创建2012年到2022年的年龄变量,我可以使用YEAR(计算的td-1),YEAR(计算的td),YEAR(计算的td + 1),YEAR逐个创建(计算td + 2)但这是一个漫长的过程。表2中的年份是重复的。请帮我一步完成。
以下是示例代码:
proc sql;
create table Forecast1(DROP=td) as
select T1.*
,date() as td
,case
when (YEAR(calculated td))- year(T1.Engine)<=10 then '0-10'
when (YEAR(calculated td))- year(T1.Engine)<=20 then '10-20'
when (YEAR(calculated td))- year(T1.Engine)<=35 then '20-35'
else '35p' end as Age_2013 format=$char5.
from gopi1.FLEET_MASTER T1
left join gopi1.ANNUAL_FH_AVERAGE T2
on T1.Model=T2.Model and T1.Age_bracket=T2.Age_bracket
答案 0 :(得分:1)
如果你在SAS,那么你应该在数据步骤中这样做。您可以在视图中执行此操作,然后将其读入SQL,如果您愿意的话。
data fleet_master_vw/view=fleet_master_vw;
set fleet_master;
array ageyr age_2012 - age_2022;
do _t = 1 to dim(ageyr);
ageyr[_t] = (your age calculation);
end;
drop _t;
run;
proc sql;
... your sql stuff, using fleet_master_vw as your source dataset ...
我认为fleet_master
包含您的年龄 - 如果需要,请更改为另一个。