首先初始数据和检验sas data set,我用excel把.xls文件转成.csv(我的sas不能直接把xls文件转成sas数据),删除你的样本文件中第一和第二行,因为我的sas不认中文,所以我改文件名为stock.csv 。
对了,文件名改掉了,我的SAS不认知中文。
当前工作文档(current folder)
/*Access raw file to data*/
libname stock "stock";
data stock.work1 (drop=x);
infile "stock\stock.csv" dsd truncover;
input stockcd : 10. trdmnt $ @;
periord+1;
input msmvttl : 16.2 mretnd : 4.16;
time_weight=msmvttl*mretnd;
cum_sum+time_weight;
if periord>24 then do;
cum_sum=0;
cum_sum+time_weight;
periord=1;
end;
run;
/*computation and data structure
only check the data in the most close two year*/
data stock.work2 (keep=stockcd cum_sum periord EV);
set stock.work1 (keep=stockcd cum_sum periord);
by stockcd;
if last.stockcd then EV=cum_sum/periord;
if periord=24 then EV=cum_sum/24;
if ev ne . and periord=24;
run;
/*generat report*/
proc print data=stock.work2 noobs;
id stockcd;
run;
proc means data=stock.work2 mean std;
var ev;
run;