- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
compute by division and ceil
weeks=ceil(abs('13jan2019'd-'31jan2019'd)/7);
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
compute by division and ceil
weeks=ceil(abs('13jan2019'd-'31jan2019'd)/7);
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.