<?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: Taking the average for each specific period in a time series dataset in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Taking-the-average-for-each-specific-period-in-a-time-series/m-p/190794#M48083</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Patrick. Could you please explain below statements in the code?&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;1.&amp;nbsp; Date='01Jan2012'd;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;2.&amp;nbsp; &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;cost=date/1000*_n_;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Thanks.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 30 Nov 2014 05:48:52 GMT</pubDate>
    <dc:creator>m1986MM</dc:creator>
    <dc:date>2014-11-30T05:48:52Z</dc:date>
    <item>
      <title>Taking the average for each specific period in a time series dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Taking-the-average-for-each-specific-period-in-a-time-series/m-p/190791#M48080</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;I have a huge dataset with more than 30m observations. The main structure of the dataset is similar to table below. However, the number of variables are 46 (not all of them useful).&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" width="576"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD class="xl63" height="15" width="96"&gt;Company_Nm&lt;/TD&gt;&lt;TD class="xl63" width="96"&gt;size &lt;/TD&gt;&lt;TD class="xl63" width="96"&gt;Brach&lt;/TD&gt;&lt;TD class="xl63" width="96"&gt;product&lt;/TD&gt;&lt;TD class="xl63" width="96"&gt;date&lt;/TD&gt;&lt;TD class="xl63" width="96"&gt;cost&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="15"&gt;X&lt;/TD&gt;&lt;TD&gt;X1&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="15"&gt;X&lt;/TD&gt;&lt;TD&gt;X2&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="15"&gt;X&lt;/TD&gt;&lt;TD&gt;X3&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="15"&gt;X&lt;/TD&gt;&lt;TD&gt;X4&lt;/TD&gt;&lt;TD&gt;D&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="15"&gt;Y&lt;/TD&gt;&lt;TD&gt;Y1&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="15"&gt;Y&lt;/TD&gt;&lt;TD&gt;Y2&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="15"&gt;Y&lt;/TD&gt;&lt;TD&gt;Y3&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="15"&gt;Y&lt;/TD&gt;&lt;TD&gt;Y4&lt;/TD&gt;&lt;TD&gt;D&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="15"&gt;Y&lt;/TD&gt;&lt;TD&gt;Y5&lt;/TD&gt;&lt;TD&gt;E&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="15"&gt;Z&lt;/TD&gt;&lt;TD&gt;Z1&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;In this dataset what I want to analyze is the cost of different product, offered by different branches of each company. The data for cost is available since 1995 in a weekly order (not similar day of the week for all of the observations).&lt;/P&gt;&lt;P&gt;Now what I want to do is taking the average cost for each product, offered by each branch, for every month. In this way I can both reduce the number on obs and analyze the price variable cross sectionally. &lt;/P&gt;&lt;P&gt;The date viable is in this format: YYYY-MM-DD. Because of the large number of variables, I prefer to not use CLASS statement. However, even if I have to use CLASS, how can I write the code to take the average for every month and create a dataset that has date (YYYY-MM) and Ave_price instead of the last two variables in the current data set.&lt;/P&gt;&lt;P&gt;I greatly appreciate any and all suggestions.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 30 Nov 2014 01:50:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Taking-the-average-for-each-specific-period-in-a-time-series/m-p/190791#M48080</guid>
      <dc:creator>m1986MM</dc:creator>
      <dc:date>2014-11-30T01:50:20Z</dc:date>
    </item>
    <item>
      <title>Re: Taking the average for each specific period in a time series dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Taking-the-average-for-each-specific-period-in-a-time-series/m-p/190792#M48081</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is a untested code, however i believe it will work for you , could you please check with you data&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table want as select product,branch,month,ym,avg(cost) as avg_cost from (select *, month(date) as month, put(date,yymmd.) as ym from test) group by product,branch,month,ym;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Jag&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 30 Nov 2014 02:52:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Taking-the-average-for-each-specific-period-in-a-time-series/m-p/190792#M48081</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2014-11-30T02:52:43Z</dc:date>
    </item>
    <item>
      <title>Re: Taking the average for each specific period in a time series dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Taking-the-average-for-each-specific-period-in-a-time-series/m-p/190793#M48082</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Below should work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; infile datalines truncover;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input Company_Id $ Branch_Id $ Prod_Id $;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format Date yymmdd10. cost dollar10.2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Date='01Jan2012'd;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Date=intnx('week',date,0,'b');&lt;/P&gt;&lt;P&gt;&amp;nbsp; do while (date&amp;lt;today());&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cost=date/1000*_n_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Date=intnx('week',date,1,'b');&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; datalines;&lt;/P&gt;&lt;P&gt;1 1 A&lt;/P&gt;&lt;P&gt;1 1 B&lt;/P&gt;&lt;P&gt;1 2 A&lt;/P&gt;&lt;P&gt;2 1 B&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table want as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Company_Id &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,Branch_Id &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,Prod_Id &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,intnx('month',Date,0,'b') as Month_Begin_Dt format=yymm7.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,avg(Cost) as avg_cost format=dollar10.2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from have&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; group by &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Company_Id &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,Branch_Id &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,Prod_Id &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,calculated Month_Begin_Dt&lt;/P&gt;&lt;P&gt;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 30 Nov 2014 04:42:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Taking-the-average-for-each-specific-period-in-a-time-series/m-p/190793#M48082</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2014-11-30T04:42:59Z</dc:date>
    </item>
    <item>
      <title>Re: Taking the average for each specific period in a time series dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Taking-the-average-for-each-specific-period-in-a-time-series/m-p/190794#M48083</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Patrick. Could you please explain below statements in the code?&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;1.&amp;nbsp; Date='01Jan2012'd;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;2.&amp;nbsp; &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;cost=date/1000*_n_;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Thanks.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 30 Nov 2014 05:48:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Taking-the-average-for-each-specific-period-in-a-time-series/m-p/190794#M48083</guid>
      <dc:creator>m1986MM</dc:creator>
      <dc:date>2014-11-30T05:48:52Z</dc:date>
    </item>
    <item>
      <title>Re: Taking the average for each specific period in a time series dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Taking-the-average-for-each-specific-period-in-a-time-series/m-p/190795#M48084</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That's just about mocking up some sample data. In 1) I need to start with some date and in 2) I just need to populate "cost" with some value. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 30 Nov 2014 08:03:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Taking-the-average-for-each-specific-period-in-a-time-series/m-p/190795#M48084</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2014-11-30T08:03:07Z</dc:date>
    </item>
    <item>
      <title>Re: Taking the average for each specific period in a time series dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Taking-the-average-for-each-specific-period-in-a-time-series/m-p/190796#M48085</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 30 Nov 2014 23:55:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Taking-the-average-for-each-specific-period-in-a-time-series/m-p/190796#M48085</guid>
      <dc:creator>m1986MM</dc:creator>
      <dc:date>2014-11-30T23:55:10Z</dc:date>
    </item>
  </channel>
</rss>

