Hello,
I have SAS date for various events and for each observation I want to determine which week of the year the event happen. However, i want that the week would start on Friday, not Sunday. How can i do this?
Thank you
Again:
data want;
set your_dataset;
week=intck('week.6', intnx('year', your_sasdatevar, 0), your_sasdatevar)+1;
run;
You need to use the INTCK function. You can specify what day of the week the function should start from, in your case Friday.
If January 1 is a Thursday, do you want the first week of the year to contain just a single day? Then January 2 through January 8 would be week 2?
yes, for example in 2018 1 week would be from 1 January till 4 January, second from 5 to 8 and so on...
I looked at INTCK function, however i need to give start and end dates, but I have a variable and i do not want to look what time period it consists every time i use it.
Hi @viollete,
Try this:
data have;
input d yymmdd8.;
format d weekdatx.;
cards;
20151231
20160101
20171228
20171229
20171231
20180101
20180104
20180105
20180907
;
data want;
set have;
wk=intck('week.6', intnx('year',d,0), d)+1;
run;
proc print data=want;
run;
@viollete wrote:
yes, for example in 2018 1 week would be from 1 January till 4 January, second from 5 to 8 and so on...
I looked at INTCK function, however i need to give start and end dates, but I have a variable and i do not want to look what time period it consists every time i use it.
One hopes that you meant the second week is 5 to 11 or we have another issue involved.
Again I ask, HOW are your intending to use this? On what duration of data? Please provide an explicit example of some date values and how you are using "Friday starting week". It likely isn't very difficult but without knowing if what you want is shift for the WEEK function, using a variation of one of the WEEKU, WEEKV or WEEKW formats, or something else it is very difficult to provide an actual solution to a-not-well-defined problem.
INTCK
start date is '01JAN18'd
end date is the date variable value
This gives you the number of weeks since January 1, 2018, and when you do it properly, it counts weeks starting on Friday
@viollete wrote:
Hello,
I have SAS date for various events and for each observation I want to determine which week of the year the event happen. However, i want that the week would start on Friday, not Sunday. How can i do this?
Thank you
You should provide some example of how this start of week on Friday is going to be used.
For example read the documentation on the WEEK function and the uses of the U, V and W descriptors on determining week number of year values returned to see some things that may need to be considered for your specific usage. For instance what if Friday is in a different calendar year? Is it still the start of your week?
I have at least 10 years period and over several millions observation. For each year, I want to find in which week the observation happened. So each year will have 1-52/53 weeks.
if sas date is between 1st January 2018 and 4th January, week=1, if between 5th January 2018 and 11th then week=2
if sa date is between 1st January 2017 and 5th January, week=1, if between 6th January 2017 and 12th then week=2
and so on...
Again:
data want;
set your_dataset;
week=intck('week.6', intnx('year', your_sasdatevar, 0), your_sasdatevar)+1;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.