Hi all,
Based on the data set below, I would like to have another col (Commence_Day) getting the date of first day of the week col(Week).
For example:
Week Commence_Day
Week31 29/07/13
Week32 05/08/13
Week33. 12/08/13
Any suggestion?
Week | COL1 | COL2 | COL3 | COL4 | COL5 | COL6 | COL7 | COL8 | COL9 | COL10 | COL11 |
Article | 4036 | 4036 | 4193 | 4193 | 4193 | 4193 | 4193 | 4193 | 4193 | 9585 | 9585 |
Week31 | 180 | 1380 | 528 | 552 | 108 | 324 | 108 | 192 | 408 | 4305 | 480 |
Week32 | 192 | 2496 | 816 | 804 | 240 | 384 | 384 | 144 | 648 | 6105 | 810 |
Week33 | 180 | 2340 | 696 | 696 | 180 | 408 | 312 | 192 | 576 | 5130 | 600 |
Week34 | 120 | 2304 | 732 | 804 | 192 | 420 | 348 | 168 | 636 | 4725 | 360 |
Week35 | 240 | 2280 | 936 | 780 | 192 | 504 | 384 | 240 | 828 | 5670 | 720 |
Week36 | 192 | 1800 | 1008 | 1296 | 240 | 648 | 588 | 264 | 996 | 6105 | 660 |
Week37 | 48 | 300 | 288 | 336 | 84 | 156 | 108 | 96 | 372 | 1110 | 255 |
The SAS calendar function intnx() will allow you to shift a week to wherever you want to. BUT: You need a SAS date value as starting point for this.
intnx('week',<sas date value>,0,'b') would give you the Sunday the week starts, intnx('week.2',<sas date value',0,'b') would give you the Monday.
The issue with your data is: You don't have a SAS date value. Your variable "Week" doesn't even say in which year this week is - which is kind of important to come up with the correct date. So to get from your data containing a string for a week number to a date some coding will be required. The data you've provided is not sufficient to do this. We need at least the year as well.
Just as an idea:
- Create a new variable with has the year and week in it, eg. WeekYear with values like '2013Week1'
- Create a data set to be used to create an informat (look up in docu: Proc Format with cntlin). The data set would have the WeekYear values in the Start variable and the SAS date values as label.
- Apply the informat on your WeekYear variable to populate a new variable containing SAS date values as required
Thank you Patrick!! I will follow your suggestions to correct this data set!! Much appreciate it!!!
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.