<?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 Calculating moving averages and price changes of past and future intervals in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calculating-moving-averages-and-price-changes-of-past-and-future/m-p/435231#M108094</link>
    <description>&lt;P&gt;I've got a dataset with 100s of companies and historic prices. The data is sorted by company and date (descending order).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to calculate a couple of variables and I was hoping to get some guidance on the best functions to use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Average price in the last 5/10/x periods (but I don't want to overlap with the previous company's data).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Price change in the last 5/10/x periods. Again, there won't be any data for this in the first 4 periods of data FOR EACH company&lt;/P&gt;
&lt;P&gt;Future price change i.e. the price in 5 periods time/price (this period)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've attached an extract from the data with Company A and Company B as an example and I've highlighted in grey the columns where I'm trying to calculate the above metrics.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm pretty sure I can use lag for the price change but not sure about the average or the future price. Also, not sure how I would go about starting the calculation for each new company i.e. Company A and Company B in the attached&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 08 Feb 2018 12:35:05 GMT</pubDate>
    <dc:creator>brophymj</dc:creator>
    <dc:date>2018-02-08T12:35:05Z</dc:date>
    <item>
      <title>Calculating moving averages and price changes of past and future intervals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-moving-averages-and-price-changes-of-past-and-future/m-p/435231#M108094</link>
      <description>&lt;P&gt;I've got a dataset with 100s of companies and historic prices. The data is sorted by company and date (descending order).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to calculate a couple of variables and I was hoping to get some guidance on the best functions to use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Average price in the last 5/10/x periods (but I don't want to overlap with the previous company's data).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Price change in the last 5/10/x periods. Again, there won't be any data for this in the first 4 periods of data FOR EACH company&lt;/P&gt;
&lt;P&gt;Future price change i.e. the price in 5 periods time/price (this period)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've attached an extract from the data with Company A and Company B as an example and I've highlighted in grey the columns where I'm trying to calculate the above metrics.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm pretty sure I can use lag for the price change but not sure about the average or the future price. Also, not sure how I would go about starting the calculation for each new company i.e. Company A and Company B in the attached&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2018 12:35:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-moving-averages-and-price-changes-of-past-and-future/m-p/435231#M108094</guid>
      <dc:creator>brophymj</dc:creator>
      <dc:date>2018-02-08T12:35:05Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating moving averages and price changes of past and future intervals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-moving-averages-and-price-changes-of-past-and-future/m-p/435253#M108109</link>
      <description>&lt;P&gt;I actually found a solution from another thread.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=sashelp.stocks out=stocks;&lt;BR /&gt; by stock date;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt; set stocks;&lt;BR /&gt; by stock;&lt;BR /&gt; retain pre1-pre12;&lt;BR /&gt; array pre(12);&lt;/P&gt;
&lt;P&gt;if first.stock then&lt;BR /&gt; do;&lt;BR /&gt; call missing(of pre(*));&lt;BR /&gt; count=0;&lt;BR /&gt; end;&lt;BR /&gt; count+1;&lt;BR /&gt; index=mod(count, 12)+1;&lt;BR /&gt; pre(index)=open;&lt;/P&gt;
&lt;P&gt;if count&amp;gt;=12 then&lt;BR /&gt; moving_average=mean(of pre(*));&lt;BR /&gt; drop count index pre1-pre12;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;proc sort data=want;&lt;BR /&gt; by stock date;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data want1;&lt;BR /&gt; set want;&lt;BR /&gt; by stock;&lt;BR /&gt; change=ifn(first.stock,.,open/lag5(open)-1);&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;proc sort data=want1;&lt;BR /&gt; by stock descending date;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2018 13:49:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-moving-averages-and-price-changes-of-past-and-future/m-p/435253#M108109</guid>
      <dc:creator>brophymj</dc:creator>
      <dc:date>2018-02-08T13:49:31Z</dc:date>
    </item>
  </channel>
</rss>

