下面的程式是 计算每年收益率累加(很单纯的将retindex加起来)
/*your xls file has been imported and translated to sas data file*/
libname stock "C:\****(路径path)*****\stock";
/*define library where stores new data set which we will used in proc freq procedure
and the translated data metioned above.
stores the output report*/
data stock.TRD_Index (drop=x);
set stock.stock;
by trddt;
retain y 1990;
x=input(trddt, yymmdd10.);
year=year(x);
if y=year then cumR+retindex;
else if y ^= year then do;
cumR=0;
cumR=cumR+retindex;
y=year;
end;
run;
/*To easy understand, I use two data steps to seperate the function of display and calculation;*/
data stock.display (keep=year cumr);
set stock.TRD_Index;
by year;
if last.year;
run;
/*only display the final cumr of the month, which is also the annual cumr*/
proc print data=stock.display;
run;
也许我对你的意图理解的不是很好,水平不高,程式也许不对
希望能帮助你
|