0

我想通过使用条件创建 2012 到 2022 的 Age 变量,我可以使用 YEAR(calculated td-1), YEAR(calculated td), YEAR(calculated td+1),YEAR(calculated 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 
4

1 回答 1

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包含您的年龄 - 如果需要,请更改为另一个。

于 2013-09-11T15:46:27.987 回答