BookmarkSubscribeRSS Feed
tekish
Quartz | Level 8

Dear expert;

how can I use the week function inside my proc report? How can I calculate the weeks and make them the title for each day of the week?

 

week 1: 04Jan21- 08Jan21

week 2: 11Jan21- 05Jan21

week 3: 18Jan21- 22Jan21

 

data have;
length Study $5 Category $9;
infile datalines;
input study $ datetime : date7. category $ value;
return;
datalines;
x 04Jan21 Category1 10
x 05Jan21 Category2 20
x 06Jan21 Category3 30
x 07Jan21 Category4 40
x 08Jan21 Category1 20
x 11Jan21 Category3 40
x 12Jan21 Category2 27
y 13Jan21 Category1 15
y 15Jan21 Category1 25
y 18Jan21 Category3 35
y 19Jan21 Category4 45
y 20Jan21 Category1 25
y 21Jan21 Category3 45
y 22Jan21 Category2 29
;
run;

proc report data=have nowd
style(summary)=Header;
title ' PROC REPORT';
column study category value,datetime value=tot;
define study / group style(column)=Header;
define category / group style(column)=Header;
define datetime /across order=internal f=date7. 'Date';
define value / analysis sum f=comma6. ' ';
define tot / analysis sum 'Total' f=comma6. ;
rbreak after / summarize;
compute after;
study='Total';
endcomp;
run;


                  
2 REPLIES 2
PhilC
Rhodochrosite | Level 12

I'm not sure I understand what you want exactly.  

 

Look here for a format:  SAS Help Center - Formats by Category

 

If you need the week number based on an index date.  There is a way using 

intck('week',...)

 

 

ballardw
Super User

@tekish wrote:

Dear expert;

how can I use the week function inside my proc report? How can I calculate the weeks and make them the title for each day of the week?

 

week 1: 04Jan21- 08Jan21

week 2: 11Jan21- 05Jan21

week 3: 18Jan21- 22Jan21

 

data have;
length Study $5 Category $9;
infile datalines;
input study $ datetime : date7. category $ value;
return;
datalines;
x 04Jan21 Category1 10
x 05Jan21 Category2 20
x 06Jan21 Category3 30
x 07Jan21 Category4 40
x 08Jan21 Category1 20
x 11Jan21 Category3 40
x 12Jan21 Category2 27
y 13Jan21 Category1 15
y 15Jan21 Category1 25
y 18Jan21 Category3 35
y 19Jan21 Category4 45
y 20Jan21 Category1 25
y 21Jan21 Category3 45
y 22Jan21 Category2 29
;
run;

proc report data=have nowd
style(summary)=Header;
title ' PROC REPORT';
column study category value,datetime value=tot;
define study / group style(column)=Header;
define category / group style(column)=Header;
define datetime /across order=internal f=date7. 'Date';
define value / analysis sum f=comma6. ' ';
define tot / analysis sum 'Total' f=comma6. ;
rbreak after / summarize;
compute after;
study='Total';
endcomp;
run;


                  

Do your dates cross, or will they for some other report, cross the year boundary in the report?

This is a critical question for a couple of reasons. One, if the data time period is long enough and all you show in the report is "Week 1" then run the risk of having data from two or more years reporting under the same "week". Second is sort order. If you expect data that crosses the year boundary to go Week 51, Week 52, Week 1, Week 2 then some approaches may be completely out.

 

Can you show us what you would like your report to look like given the example data provided?

 

BTW,Bad juju (or karma, take your pick) accrues to people using SAS that call date values "datetime". It can lead to a lot of confusion because SAS datetime values are measured in seconds and date values are measured in days. We have numerous examples on this forum where people talk about "dates" that are datetimes or datetimes that are dates in reality. Often it takes number of questions to force the questioner to reveal that information because the reported behavior isn't possible with the proper name/value match up. (Character values are completely out of the discussion as they are neither.)

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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