<?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 Sum daily values by rolling 52 weekly periods in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Sum-daily-values-by-rolling-52-weekly-periods/m-p/64708#M6516</link>
    <description>This seems like it should be fairly easy but I am not having much luck in EG.  I have a table with multiple columns and a new row/record for each day.  I would like to sum the daily columns values by weeks.  I would also like to have the weeks roll on a 52 week basis.  Any suggestions would be welcome.</description>
    <pubDate>Fri, 05 Dec 2008 16:03:29 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2008-12-05T16:03:29Z</dc:date>
    <item>
      <title>Sum daily values by rolling 52 weekly periods</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Sum-daily-values-by-rolling-52-weekly-periods/m-p/64708#M6516</link>
      <description>This seems like it should be fairly easy but I am not having much luck in EG.  I have a table with multiple columns and a new row/record for each day.  I would like to sum the daily columns values by weeks.  I would also like to have the weeks roll on a 52 week basis.  Any suggestions would be welcome.</description>
      <pubDate>Fri, 05 Dec 2008 16:03:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Sum-daily-values-by-rolling-52-weekly-periods/m-p/64708#M6516</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-12-05T16:03:29Z</dc:date>
    </item>
    <item>
      <title>Re: Sum daily values by rolling 52 weekly periods</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Sum-daily-values-by-rolling-52-weekly-periods/m-p/64709#M6517</link>
      <description>INTNX function can be used to derive a "week start date" by/group variable and also a "52-week period start date".  Here is some sample code for generating the 52-week start date value using today's date as the INTNX argument-1:&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
date_value = today();&lt;BR /&gt;
wk52pd_start_date = intnx('week',date_value,-52);&lt;BR /&gt;
format date_value wk52pd_start_date date9. ;&lt;BR /&gt;
put _all_;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Fri, 05 Dec 2008 16:36:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Sum-daily-values-by-rolling-52-weekly-periods/m-p/64709#M6517</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2008-12-05T16:36:45Z</dc:date>
    </item>
    <item>
      <title>Re: Sum daily values by rolling 52 weekly periods</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Sum-daily-values-by-rolling-52-weekly-periods/m-p/64710#M6518</link>
      <description>From your post, I take it your data looks roughly like:&lt;BR /&gt;
&lt;BR /&gt;
SaleDate  SaleAmt&lt;BR /&gt;
01Apr2008  $15&lt;BR /&gt;
02Apr2008  $20&lt;BR /&gt;
...&lt;BR /&gt;
01May2008 $10&lt;BR /&gt;
...&lt;BR /&gt;
&lt;BR /&gt;
If I'm on the right track, here's a sketch of one way you could tackle this:&lt;BR /&gt;
&lt;BR /&gt;
1. If you want totals by week, you can get that using a computed column and some summarization in the Filter and Query. Using the above data, here's what I'd do. Create a computed column -- say, Week_Number -- with Build Expression. Expression should look something like  &lt;I&gt;week(aprsales.SaleDate )&lt;/I&gt;. The WEEK function is new to SAS 9, so you won't see it in the list of EG functions but you can still type it into the expression (assuming you're running SAS 9). More documentation on the function is here:&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/59540/HTML/default/a003154994.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/59540/HTML/default/a003154994.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
To be on the safe side, create a second new column from an expression -- Year -- like &lt;I&gt;year(aprsales.SaleDate )&lt;/I&gt;.&lt;BR /&gt;
&lt;BR /&gt;
2. Once you have the computed columns Week_Number and Year, then get Week_Number, Year, and SaleAmt in the Select Data. Change Summarization on SaleAmt to SUM. In Summary Groups below the Select Data, click Edit Summary Groups and move Year and Week_Number into the Group By.&lt;BR /&gt;
&lt;BR /&gt;
When you run the task, that should give you totals by year and week for all your data. To get the rolling 52 week behavior, that would be some sort of filter based on dates. Scott's code could be a useful technique here, along with something like a TODAY function in the filter to automate getting the appropriate 52-week window.&lt;BR /&gt;
&lt;BR /&gt;
Best,&lt;BR /&gt;
&lt;BR /&gt;
Richard</description>
      <pubDate>Mon, 08 Dec 2008 16:03:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Sum-daily-values-by-rolling-52-weekly-periods/m-p/64710#M6518</guid>
      <dc:creator>RichardH_sas</dc:creator>
      <dc:date>2008-12-08T16:03:07Z</dc:date>
    </item>
  </channel>
</rss>

