Seems like what you want is to extract the day of the month, divide that by 7 and take the ceiling of the result:
DayMo = Day(Date);
WeekMo = ceil(DayMo/7);
But that would get you week3 for January 16, not week2
There are, believe it or not, several of definitons for "week" when it comes to use.
Does your "week" start on Sunday, Monday or some other day? Or is week the first 7 days of a month regardless of starting day of the week?
Does it count as week one if there is only one day in that week? 2 days? 3 days?
Seems like what you want is to extract the day of the month, divide that by 7 and take the ceiling of the result:
DayMo = Day(Date);
WeekMo = ceil(DayMo/7);
But that would get you week3 for January 16, not week2
The definition is pretty critical as you are saying that 1/16/2016 is in week 2 bu tis the 3rd Saturday of January 2016 while 1/1/2016 is in week 1 as the first Friday. So are the dates between 3 and 9 january week 1 or week2?
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!
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.