<?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 Re: Rolling average returns in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Rolling-average-returns/m-p/364113#M86317</link>
    <description>&lt;P&gt;You have CRSP monthly data, sorted by PERMNO/DATE, where DATE is the last trading date of the month.&amp;nbsp; You want rolling 12 months average returns (monthly average, or yearly?)&amp;nbsp; (arithmetic average or geometric mean?).&amp;nbsp; Below is geometric mean monthly return for rolling 12-month window.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; do seq=1 by 1 until(last.permno);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; by permno;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;log_1plus_ret=log(1+ret);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;L12=ifn(seq&amp;lt;=12,0,lag12(log_1plus_ret));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; sumlogs=sum(sumlogs,log_1plus_ret)-L12;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if seq&amp;lt;=11 then continue;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; geomeanret12=exp(sumlog12/12)-1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that this program assumes there are no "holes" in the monthly series for any permno.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 04 Jun 2017 12:14:16 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2017-06-04T12:14:16Z</dc:date>
    <item>
      <title>Rolling average returns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-average-returns/m-p/364024#M86275</link>
      <description>&lt;P&gt;Hello!&lt;BR /&gt;&lt;BR /&gt;I'm trying to do rolling average returns for each "bemedeciles" (Or groups), from Aprile (t) to Aprile (t+1), Aprile (t+1) to (Aprile t+2) and so on.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;The thing that I'm struggling is how to do it. I've search the entire internet, but not found a quite "understandable" methods to do it.&amp;nbsp;&lt;BR /&gt;The part where it stops is how to get the rolling average returns in those intervals, based on "Names date", and "bemedecile".&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Can someone please help me? I'm on ground zero, no progress on it for 1 day now.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data:&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/9218i78A3555E18AE8300/image-size/original?v=1.0&amp;amp;px=-1" border="0" alt="sascom.PNG" title="sascom.PNG" /&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Jun 2017 17:00:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-average-returns/m-p/364024#M86275</guid>
      <dc:creator>TorTheHammer</dc:creator>
      <dc:date>2017-06-03T17:00:48Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling average returns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-average-returns/m-p/364026#M86277</link>
      <description>&lt;P&gt;It would help if you could provide have and want datasets in the form of datasteps. From your description it looks like you are only attempting to get averages of each adjacent pair of values, within each group, in your datastep&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Jun 2017 17:42:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-average-returns/m-p/364026#M86277</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-06-03T17:42:39Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling average returns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-average-returns/m-p/364027#M86278</link>
      <description>&lt;P&gt;I agree that there's a lot out there. Here's a post from Rick that lists many of the options:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.sas.com/content/iml/2016/01/27/moving-average-in-sas.html" target="_blank"&gt;http://blogs.sas.com/content/iml/2016/01/27/moving-average-in-sas.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think you want the second example here - with BY groups:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/kb/25/027.html" target="_blank"&gt;http://support.sas.com/kb/25/027.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In general, we can't really help off a picture, for starters we'd have to type it out if we want to work with your data, which many will not do. So a 'generic' question will get 'generic' answers.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Jun 2017 17:56:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-average-returns/m-p/364027#M86278</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-06-03T17:56:51Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling average returns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-average-returns/m-p/364072#M86299</link>
      <description>&lt;P&gt;Here is an example.(if you do not have a big table)&lt;/P&gt;
&lt;P&gt;Length of rolling windows is a month forward.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data air;
 set sashelp.air;
 if mod(_n_,100)=1 then group+1;
run;


proc sql;
create table want as
 select *,(select mean(air) from air where group=a.group and
 date between a.date and intnx('month',a.date,1,'s')) as rolling_mean
  from air as a;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 04 Jun 2017 02:41:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-average-returns/m-p/364072#M86299</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-06-04T02:41:37Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling average returns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-average-returns/m-p/364113#M86317</link>
      <description>&lt;P&gt;You have CRSP monthly data, sorted by PERMNO/DATE, where DATE is the last trading date of the month.&amp;nbsp; You want rolling 12 months average returns (monthly average, or yearly?)&amp;nbsp; (arithmetic average or geometric mean?).&amp;nbsp; Below is geometric mean monthly return for rolling 12-month window.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; do seq=1 by 1 until(last.permno);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; by permno;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;log_1plus_ret=log(1+ret);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;L12=ifn(seq&amp;lt;=12,0,lag12(log_1plus_ret));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; sumlogs=sum(sumlogs,log_1plus_ret)-L12;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if seq&amp;lt;=11 then continue;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; geomeanret12=exp(sumlog12/12)-1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that this program assumes there are no "holes" in the monthly series for any permno.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 04 Jun 2017 12:14:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-average-returns/m-p/364113#M86317</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-06-04T12:14:16Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling average returns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-average-returns/m-p/364167#M86329</link>
      <description>&lt;P&gt;First of all, thank you very much for your response!&lt;BR /&gt;&lt;BR /&gt;Yes, I want yearly average returns (From the monthly).&lt;BR /&gt;&lt;BR /&gt;Otherwise, yes I want geometric mean.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Thank you &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 04 Jun 2017 22:08:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-average-returns/m-p/364167#M86329</guid>
      <dc:creator>TorTheHammer</dc:creator>
      <dc:date>2017-06-04T22:08:03Z</dc:date>
    </item>
  </channel>
</rss>

