DATA Step, Macro, Functions and more

How to get week1 week2 week3 week4 based on date

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 80
Accepted Solution

How to get week1 week2 week3 week4 based on date

Hi I have a table that has a date column I need to determine what week out of the month was it week1 week2 week3 week4...enclose is a sample of what I have an what I need it to look

Id. Date
A1. 01/01/16
A2. 01/16/16
A1. 01/26/16



Want
Id. Date. Week
A1. 01/01/16. Week1
A2. 01/16/16. Week2
A1. 01/26/16. Week4

thanks in advance

Accepted Solutions
Solution
‎05-26-2016 05:41 PM
Frequent Contributor
Posts: 102

Re: How to get week1 week2 week3 week4 based on date

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

View solution in original post


All Replies
Super User
Posts: 11,343

Re: How to get week1 week2 week3 week4 based on date

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?

Solution
‎05-26-2016 05:41 PM
Frequent Contributor
Posts: 102

Re: How to get week1 week2 week3 week4 based on date

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

Super User
Posts: 11,343

Re: How to get week1 week2 week3 week4 based on date

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?

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 273 views
  • 1 like
  • 3 in conversation