BookmarkSubscribeRSS Feed
srinivaschary
Calcite | Level 5

Hi,

I have task date range please help me for the below scenorios.

 

i need to group with Sunday to Saturday  as Week1 in perticular month for example,

 

March 5th to March 11th it would be "Week1 March"  and March 12th To March 18th it would be "Week2 March"

 

 

 

Thanks,

Srinivas

 

 

 

5 REPLIES 5
andreas_lds
Jade | Level 19

Please post an example data-set and the requested result dataset.

Kurt_Bremser
Super User

Use the weekday() function to determine Sundays, and then count the week in a retained variable:

data have;
do day_date = '01mar2017'd to '31mar2017'd;
  output;
end;
format day_date yymmddd10.;
run;

data want;
set have;
retain weekno 0;
length weektext $30;
if weekday(day_date) = 1 then weekno + 1;
if weekno > 0 then weektext = "Week" !! strip(put(weekno,2.)) !! " " !! strip(put(day_date,monname.));
drop weekno;
run;

proc print data=want noobs;
run;

Result:

  day_date     weektext

2017-03-01               
2017-03-02               
2017-03-03               
2017-03-04               
2017-03-05    Week1 March
2017-03-06    Week1 March
2017-03-07    Week1 March
2017-03-08    Week1 March
2017-03-09    Week1 March
2017-03-10    Week1 March
2017-03-11    Week1 March
2017-03-12    Week2 March
2017-03-13    Week2 March
2017-03-14    Week2 March
2017-03-15    Week2 March
2017-03-16    Week2 March
2017-03-17    Week2 March
2017-03-18    Week2 March
2017-03-19    Week3 March
2017-03-20    Week3 March
2017-03-21    Week3 March
2017-03-22    Week3 March
2017-03-23    Week3 March
2017-03-24    Week3 March
2017-03-25    Week3 March
2017-03-26    Week4 March
2017-03-27    Week4 March
2017-03-28    Week4 March
2017-03-29    Week4 March
2017-03-30    Week4 March
2017-03-31    Week4 March
Sastech
Fluorite | Level 6

Hi Sir @Kurt_Bremser

 

What you have given is good for the single ID in the table but we have multiple ids and each ids has a row. 

Example data :

ID NameFrom date To date 
1a03-25-202309-11-2023
2b01-07-202205-10-2023
3c10-07-202312-18-2023

 

 

ballardw
Super User

@Sastech 

If your problem/question is about different data then you should start your own thread. Where it is related to another thread you can post a link to it by copying the the URL from your browser and posting into your message.

 

Since your data is quite different to start with you have to show an example of what you expect for output.

I have no idea what you expect as you provided no details just that your data is different and multiple ids. Nothing about how the ID would affect the output. Nothing about what the values should be.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 5 replies
  • 5330 views
  • 0 likes
  • 6 in conversation