turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- Learning SAS...need help with mathematical functio...

Topic Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

05-21-2011 10:53 AM

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

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

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to KyleS83

05-21-2011 01:06 PM

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

proc means data=datasetname mean;

var avgreturn;

run;

Regards,

Mark

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to KyleS83

05-22-2011 08:42 PM

If you want dataset.

[pre]

proc means data=datasetname ;

var avgreturn;

output out=sum_var mean=avg;

run;

[/pre]

Ksharp

[pre]

proc means data=datasetname ;

var avgreturn;

output out=sum_var mean=avg;

run;

[/pre]

Ksharp

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to KyleS83

05-24-2011 03:47 PM

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

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