BookmarkSubscribeRSS Feed
KyleS83
Calcite | Level 5
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
3 REPLIES 3
mfisher
Fluorite | Level 6
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
Ksharp
Super User
If you want dataset.
[pre]
proc means data=datasetname ;
var avgreturn;
output out=sum_var mean=avg;
run;
[/pre]

Ksharp
Peter_C
Rhodochrosite | Level 12
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

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1195 views
  • 0 likes
  • 4 in conversation