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 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 5 replies
  • 5979 views
  • 0 likes
  • 6 in conversation