我有一个日期(月),人和回报(每月)的数据集。我需要计算每个人从4月份t到3月份t + 1的数据集的复合月度回报。 例如,
年度回报人A = 4月1年* 5月1 * * * 3月2年。
我可以知道在SAS中如何做到这一点?我需要一个阵列吗?
答案 0 :(得分:0)
您的意思是您的数据集看起来像
日期,人物,回归
“01Apr2009”d,A,1.1
等
等
/* Then you can do */
data ur_input_data_view / view = ur_input_data_view;
/* assuming your dataset is stored in ur_input_data */
set ur_input_data;
/* obtain the year and month from the date variable */
year = year(date);
mth = year(date);
run;
/* you can skip the sort if your data is already sorted by person then date */
proc sort data = ur_input_data;
by person date;
run;
data output_data;
set ur_input_data_view ;
by person date;
/* reset annual return to null if looking at a new person or month is april */
if first.person or mth = 4 then do;
annual_return = return;
end;
retain annual_return;
annual_return = annual_return * return;
/* this will output nothing for the persons that don't have a record at march */
if mth = 3 then output;
run;