<?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: How to create rolling 1 year average value for a particular combination? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-rolling-1-year-average-value-for-a-particular/m-p/162298#M42166</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;never mind, first part was good enough to solve the problem&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 28 Sep 2014 18:49:49 GMT</pubDate>
    <dc:creator>munitech4u</dc:creator>
    <dc:date>2014-09-28T18:49:49Z</dc:date>
    <item>
      <title>How to create rolling 1 year average value for a particular combination?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-rolling-1-year-average-value-for-a-particular/m-p/162290#M42158</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have 4 columns as:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Week Key Product Value&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to roll up 52 weeks and replace the value for the last week(for combination of key and its product and its corresponding value) with average of 52 weeks for same combination, and keep doing so till the last week by 52 weeks average.,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Week Key Product Value&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 541&amp;nbsp; A&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1.6&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 542&amp;nbsp; B&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6.4&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 541&amp;nbsp; A&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8.4&lt;/P&gt;&lt;P&gt;...............................&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;98&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 541&amp;nbsp; A&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3.4&lt;/P&gt;&lt;P&gt;98&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 542&amp;nbsp; B&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4.5&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So i want to roll up week 1-52 into week 1 and make 541-A combination values as average of that period and so for 542-B combination and move on for week 2-53, 3-54 and keep doing that for both the combinations.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Sep 2014 16:48:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-create-rolling-1-year-average-value-for-a-particular/m-p/162290#M42158</guid>
      <dc:creator>munitech4u</dc:creator>
      <dc:date>2014-09-26T16:48:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to create rolling 1 year average value for a particular combination?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-rolling-1-year-average-value-for-a-particular/m-p/162291#M42159</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;could you please clarify what you want to do more?&lt;/P&gt;&lt;P&gt;with example of data even with three observation&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Sep 2014 18:34:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-create-rolling-1-year-average-value-for-a-particular/m-p/162291#M42159</guid>
      <dc:creator>mohamed_zaki</dc:creator>
      <dc:date>2014-09-26T18:34:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to create rolling 1 year average value for a particular combination?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-rolling-1-year-average-value-for-a-particular/m-p/162292#M42160</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not tested code :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;proc sql;
create table want as
 select a.*,( select avg(value) from have where key=a.key and product=a.product and week lt week+52 )&amp;nbsp; as new_value
&amp;nbsp; from have as a&amp;nbsp; ;
quit;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 27 Sep 2014 10:44:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-create-rolling-1-year-average-value-for-a-particular/m-p/162292#M42160</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-09-27T10:44:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to create rolling 1 year average value for a particular combination?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-rolling-1-year-average-value-for-a-particular/m-p/162293#M42161</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Its giving only one average value for all the weeks combined.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 27 Sep 2014 11:23:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-create-rolling-1-year-average-value-for-a-particular/m-p/162293#M42161</guid>
      <dc:creator>munitech4u</dc:creator>
      <dc:date>2014-09-27T11:23:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to create rolling 1 year average value for a particular combination?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-rolling-1-year-average-value-for-a-particular/m-p/162294#M42162</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I got some replies at stackover flow: &lt;A href="http://stackoverflow.com/questions/26073862/how-to-create-rolling-average-data" title="http://stackoverflow.com/questions/26073862/how-to-create-rolling-average-data"&gt;sql - How to create rolling average data? - Stack Overflow&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But they are using some sql functions which are not compatible with proc sql. Maybe somebody can tweak their idea?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 27 Sep 2014 11:45:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-create-rolling-1-year-average-value-for-a-particular/m-p/162294#M42162</guid>
      <dc:creator>munitech4u</dc:creator>
      <dc:date>2014-09-27T11:45:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to create rolling 1 year average value for a particular combination?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-rolling-1-year-average-value-for-a-particular/m-p/162295#M42163</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is it what you are looking for ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data x;
key=541;product='A';output;
key=542;product='B';output;
run;
data have;
 set x;
 do week=1 to 98;
&amp;nbsp; value=ranuni(0)*10;
&amp;nbsp; output;
 end;
run;
proc sort data=have;by week key product;run;


proc sql;
create table want as
 select a.*,( select avg(value) from have where key=a.key and product=a.product and a.week le week le a.week+51 )&amp;nbsp; as new_value
&amp;nbsp; from have as a&amp;nbsp; ;
quit;




&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: xia keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 27 Sep 2014 13:05:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-create-rolling-1-year-average-value-for-a-particular/m-p/162295#M42163</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-09-27T13:05:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to create rolling 1 year average value for a particular combination?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-rolling-1-year-average-value-for-a-particular/m-p/162296#M42164</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks a lot!! But only problem remains is that new value wont be for first week, but week 52(1-52),53(2-53) and so on. I know I can simply add 52 to week number, but can i do that during sql step itself?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 27 Sep 2014 15:44:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-create-rolling-1-year-average-value-for-a-particular/m-p/162296#M42164</guid>
      <dc:creator>munitech4u</dc:creator>
      <dc:date>2014-09-27T15:44:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to create rolling 1 year average value for a particular combination?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-rolling-1-year-average-value-for-a-particular/m-p/162297#M42165</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;"&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt; that new value wont be for first week, but week 52(1-52),53(2-53) and so on.&lt;/SPAN&gt;"&lt;/P&gt;&lt;P&gt;What does that mean ? Don't you want rolling a window which has a 52 week ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 28 Sep 2014 11:56:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-create-rolling-1-year-average-value-for-a-particular/m-p/162297#M42165</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-09-28T11:56:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to create rolling 1 year average value for a particular combination?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-rolling-1-year-average-value-for-a-particular/m-p/162298#M42166</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;never mind, first part was good enough to solve the problem&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 28 Sep 2014 18:49:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-create-rolling-1-year-average-value-for-a-particular/m-p/162298#M42166</guid>
      <dc:creator>munitech4u</dc:creator>
      <dc:date>2014-09-28T18:49:49Z</dc:date>
    </item>
  </channel>
</rss>

