BookmarkSubscribeRSS Feed
sefcikm
Calcite | Level 5

I have a date field that was formatted as DATE9. and then I changed it to YYWEEKU7. I am now trying to aggregate by that new weekly formatted date but it is not aggregating properly. I think the day is still stored in the background so when I sum my values it is summing down to the daily level, instead of weekly level. Is there a way to work around this other than changing the field to a character field and summing by that?

3 REPLIES 3
ballardw
Super User

@sefcikm wrote:

I have a date field that was formatted as DATE9. and then I changed it to YYWEEKU7. I am now trying to aggregate by that new weekly formatted date but it is not aggregating properly. I think the day is still stored in the background so when I sum my values it is summing down to the daily level, instead of weekly level. Is there a way to work around this other than changing the field to a character field and summing by that?


Please show EXACTLY how you are "summing down". And example of some starting data and what you expect for a result is helpful.

 

I strongly suspect you are doing something manually in a data step that is trivial with one of the procedures like Means, Tabulate or Report.

Do you need a data set (for further manipulation) or a report that people read?

 

 

 

sefcikm
Calcite | Level 5

Below is a simplified version of what I am working with. The date field is a date9. format. I then took that date field and used it to make the week field by changing the format to yyweek07. I am using SAS Enterprise Guide for this and just changed the format in the query builder using 'Date' as my source column. I am now trying to sum the revenue across the week field to get something like the second table I shared below. When I got to sum though, it isn't summing to the week level. The output of this is just a dataset that I will then be working with further. 

 

DateWeekRevenue
01JAN20202020W01500
02JAN20202020W01200
01FEB20202020W04300
02FEB20202020W04200

 

 

WeekRevenue
2020W01700
2020W04500
ballardw
Super User

Can you show the code generated by the query builder?

 

And instead of "query builder" you might be looking for a "summarize" task

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1000 views
  • 0 likes
  • 2 in conversation