I'm learning base SAS programming at the moment. This is part of my SAS data set that shows the average return of stocks after a 9 year period from 20 different companies. I want to calculate the average of this variable (average of the AvgReturn). I tried doing mean(AvgReturn) but it doesn't work. I prefer not to input all the numbers so how would I go about this?
This will calculate the overall mean of avgreturn and the result will appear in your output window. You can also use proc univariate and proc summary to do the same (proc summary produces an output dataset only).
proc means data=datasetname mean;
a note of caution
a return of +10% followed by -10% might not average at an average return of zero, but to -.5%
This is because rates of return are usually considered cumulative. 1.5% per month is not 18% per year but the product of 1.5% each month like
(1.015)**12 -1 =19.56%
Typically the compound rate over a period is a bit like
To express this as an average per period, we take the N-th root of the product of N periods, which in SAS syntax, would be like:
( (1+rate1/100)*(1+rate2/100)*(1+rate3/100) ) ** ( 1/3 ) for the average over 3 periods.
This kind of average rate of return can be measured in a data step, like
data ave_returns ;
input aveReturn ;
format simple_ave_return 8.2 cum_ave_return percent8.2 ;
simple_cum + aveReturn ;
simple_ave_return = simple_cum / _n_ ;
* for (more correct= compound) average return ;
retain compounder 1 ;
compounder = compounder * (1 + aveReturn/100 ) ;
cum_ave_return = compounder ** ( 1/_n_) -1 ;
cards/* your numbers follow*/ ;
proc print ;
SAS has some financial functions which can help when your "rates" are available within the observation. For Internal Rate of Return, see http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000245904.htm