<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Learning SAS...need help with mathematical functions in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Learning-SAS-need-help-with-mathematical-functions/m-p/68142#M19513</link>
    <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
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? &lt;BR /&gt;
&lt;BR /&gt;
Thanks!&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
  AvgReturn&lt;BR /&gt;
                       &lt;BR /&gt;
      11.24&lt;BR /&gt;
       5.45&lt;BR /&gt;
      11.57&lt;BR /&gt;
      -1.69&lt;BR /&gt;
      17.79&lt;BR /&gt;
      11.03&lt;BR /&gt;
       6.61&lt;BR /&gt;
       1.88&lt;BR /&gt;
       1.49&lt;BR /&gt;
      14.15&lt;BR /&gt;
      29.47&lt;BR /&gt;
       0.03&lt;BR /&gt;
       9.73&lt;BR /&gt;
      19.66&lt;BR /&gt;
       4.11&lt;BR /&gt;
      12.51&lt;BR /&gt;
       6.84&lt;BR /&gt;
       7.62&lt;BR /&gt;
       -0.64&lt;BR /&gt;
        0.63</description>
    <pubDate>Sat, 21 May 2011 14:53:06 GMT</pubDate>
    <dc:creator>KyleS83</dc:creator>
    <dc:date>2011-05-21T14:53:06Z</dc:date>
    <item>
      <title>Learning SAS...need help with mathematical functions</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Learning-SAS-need-help-with-mathematical-functions/m-p/68142#M19513</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
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? &lt;BR /&gt;
&lt;BR /&gt;
Thanks!&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
  AvgReturn&lt;BR /&gt;
                       &lt;BR /&gt;
      11.24&lt;BR /&gt;
       5.45&lt;BR /&gt;
      11.57&lt;BR /&gt;
      -1.69&lt;BR /&gt;
      17.79&lt;BR /&gt;
      11.03&lt;BR /&gt;
       6.61&lt;BR /&gt;
       1.88&lt;BR /&gt;
       1.49&lt;BR /&gt;
      14.15&lt;BR /&gt;
      29.47&lt;BR /&gt;
       0.03&lt;BR /&gt;
       9.73&lt;BR /&gt;
      19.66&lt;BR /&gt;
       4.11&lt;BR /&gt;
      12.51&lt;BR /&gt;
       6.84&lt;BR /&gt;
       7.62&lt;BR /&gt;
       -0.64&lt;BR /&gt;
        0.63</description>
      <pubDate>Sat, 21 May 2011 14:53:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Learning-SAS-need-help-with-mathematical-functions/m-p/68142#M19513</guid>
      <dc:creator>KyleS83</dc:creator>
      <dc:date>2011-05-21T14:53:06Z</dc:date>
    </item>
    <item>
      <title>Re: Learning SAS...need help with mathematical functions</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Learning-SAS-need-help-with-mathematical-functions/m-p/68143#M19514</link>
      <description>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).&lt;BR /&gt;
&lt;BR /&gt;
proc means data=datasetname mean;&lt;BR /&gt;
var avgreturn;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
&lt;BR /&gt;
Mark</description>
      <pubDate>Sat, 21 May 2011 17:06:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Learning-SAS-need-help-with-mathematical-functions/m-p/68143#M19514</guid>
      <dc:creator>mfisher</dc:creator>
      <dc:date>2011-05-21T17:06:48Z</dc:date>
    </item>
    <item>
      <title>Re: Learning SAS...need help with mathematical functions</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Learning-SAS-need-help-with-mathematical-functions/m-p/68144#M19515</link>
      <description>If you want dataset.&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc means data=datasetname ;&lt;BR /&gt;
var avgreturn;&lt;BR /&gt;
output out=sum_var mean=avg;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Mon, 23 May 2011 00:42:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Learning-SAS-need-help-with-mathematical-functions/m-p/68144#M19515</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-05-23T00:42:03Z</dc:date>
    </item>
    <item>
      <title>Re: Learning SAS...need help with mathematical functions</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Learning-SAS-need-help-with-mathematical-functions/m-p/68145#M19516</link>
      <description>Kyle&lt;BR /&gt;
a note of caution&lt;BR /&gt;
a return of +10% followed by -10% might not average at an average return of zero, but to -.5%&lt;BR /&gt;
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&lt;BR /&gt;
(1.015)**12 -1  =19.56%&lt;BR /&gt;
&lt;BR /&gt;
Typically the compound rate over a period is a bit like&lt;BR /&gt;
 (1+rate1/100)*(1+rate2/100)*(1+rate3/100) -1 &lt;BR /&gt;
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:&lt;BR /&gt;
(  (1+rate1/100)*(1+rate2/100)*(1+rate3/100)  ) ** ( 1/3 ) for the average over 3 periods.&lt;BR /&gt;
&lt;BR /&gt;
This kind of average rate of return can be measured in a data step, like&lt;BR /&gt;
data ave_returns ;&lt;BR /&gt;
input aveReturn ;&lt;BR /&gt;
format simple_ave_return 8.2 cum_ave_return percent8.2 ; &lt;BR /&gt;
simple_cum + aveReturn ;&lt;BR /&gt;
simple_ave_return = simple_cum / _n_ ;&lt;BR /&gt;
* for (more correct= compound) average return ;&lt;BR /&gt;
retain compounder 1 ;&lt;BR /&gt;
compounder = compounder * (1 + aveReturn/100 ) ;&lt;BR /&gt;
cum_ave_return = compounder ** ( 1/_n_) -1 ;&lt;BR /&gt;
cards/* your numbers follow*/ ;&lt;BR /&gt;
;&lt;BR /&gt;
run ;&lt;BR /&gt;
proc print ;&lt;BR /&gt;
run ;&lt;BR /&gt;
SAS has some financial functions which can help when your "rates" are available within the observation. For Internal Rate of Return, see &lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000245904.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000245904.htm&lt;/A&gt; &lt;BR /&gt;
 &lt;BR /&gt;
peterC</description>
      <pubDate>Tue, 24 May 2011 19:47:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Learning-SAS-need-help-with-mathematical-functions/m-p/68145#M19516</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-05-24T19:47:08Z</dc:date>
    </item>
  </channel>
</rss>

