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.
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:
date_value = today();
wk52pd_start_date = intnx('week',date_value,-52);
format date_value wk52pd_start_date date9. ;
If I'm on the right track, here's a sketch of one way you could tackle this:
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 week(aprsales.SaleDate ). 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:
To be on the safe side, create a second new column from an expression -- Year -- like year(aprsales.SaleDate ).
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.
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.