Help using Base SAS procedures

Learning SAS...need help with mathematical functions

Reply
Occasional Contributor
Posts: 9

Learning SAS...need help with mathematical functions

Hi,

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?

Thanks!



AvgReturn

11.24
5.45
11.57
-1.69
17.79
11.03
6.61
1.88
1.49
14.15
29.47
0.03
9.73
19.66
4.11
12.51
6.84
7.62
-0.64
0.63
Contributor
Posts: 58

Re: Learning SAS...need help with mathematical functions

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;
var avgreturn;
run;

Regards,

Mark
Super User
Posts: 10,035

Re: Learning SAS...need help with mathematical functions

If you want dataset.
[pre]
proc means data=datasetname ;
var avgreturn;
output out=sum_var mean=avg;
run;
[/pre]

Ksharp
Valued Guide
Posts: 2,177

Re: Learning SAS...need help with mathematical functions

Kyle
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
(1+rate1/100)*(1+rate2/100)*(1+rate3/100) -1
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*/ ;
;
run ;
proc print ;
run ;
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

peterC
Ask a Question
Discussion stats
  • 3 replies
  • 318 views
  • 0 likes
  • 4 in conversation