BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
hk2013
Fluorite | Level 6

data _null_;
call symput('Begin_Date',compress("'"||put(intnx('week1.2',TODAY(),-1,'E'),date9.)||"'d"));
call symput('End_Date',compress("'"||put(intnx('Month',TODAY(),0,'E'),date9.)||"'d"));
call symput('Number_week',INTCK('Week',&Begin_Date,&End_Date,'C') );
run;

 

i am trying to get number of weeks between two dates. i have something that is working but its not coming out to be what i expect. 

 

from jan 13 2019 to jan 31 2019 shouldnt that be three weeks but i am only getthing 2 week how do i round up when end of month falls mid week.

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

compute by division and ceil

 

weeks=ceil(abs('13jan2019'd-'31jan2019'd)/7);

View solution in original post

4 REPLIES 4
novinosrin
Tourmaline | Level 20

compute by division and ceil

 

weeks=ceil(abs('13jan2019'd-'31jan2019'd)/7);
hk2013
Fluorite | Level 6

thank you! 

SASKiwi
PROC Star

There are any number of definitions for a week. You can't assume your definition is the only one.

 

For example, does your week definition start on Sun, Mon or some other day? Or is it just the number of 7-day periods from your starting date to your end date? Do you cater for part-weeks? Your example Jan 13 2019 to Jan 31 2019 could be just 2 weeks if you are only counting whole weeks or 2.57 weeks if you count decimals, or 3 weeks if you consider any day over 2 weeks from your starting date now means you are in your third week.

 

You need to start by explaining what your definition of a week is.

ballardw
Super User

You may also want to examine the documentation for the WEEKU, WEEKV and WEEKW formats for some of the issues involved with weeks and treatments at beginning and ending of years.

 

And when I look at a calendar between 13 Jan 2019 and 31 Jan 2019 I would expect to get 2 weeks. Which day of the week to expect the week to start on? SAS treats Sunday, which 13 Jan 2019 was, as the start of week, the next week starts on 20 Jan (1 week interval) and the then 27 Jan starts a week (2 week interval).

 

Note that intck returns intervals, or 1 for adjacent days such as 13Jan2019 and 14Jan2019. So if you need to count days including the end dates you need to add 1. Perhaps that is what you need to do with your definition/need of week counts.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 6920 views
  • 2 likes
  • 4 in conversation