- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I am trying to get number of working days by using intck('weekday', start,end). But the following code and the result confused me:
data _null_;
days1=intck('WEEKDAY', '02jul2016'd , '05jul2016'd );
days2=intck('WEEKDAY', '04jul2016'd , '07jul2016'd );
put "days1=" days1 "days2=" days2;
run;
The result is:
days1=2 days2=3
Days2 value is what I expected. But what I expected for days1 was 1 instead of 2, since '02jul2016'd is Saturday and i am only counting weekdays which is Mon-Fri. So acturally days1 is calculating # of days between '04jul2016'd and '05jul2016'd. So it should be 1 day.
How does intck really work?
Thanks,
EEEY
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data _null_;
D1=intck('WEEKDAY', '05jul2016'd , '05jul2016'd ); putlog D1=;
D2=intck('WEEKDAY', '04jul2016'd , '05jul2016'd ); putlog D2=;
D3=intck('WEEKDAY', '03jul2016'd , '05jul2016'd ); putlog D3=;
D4=intck('WEEKDAY', '02jul2016'd , '05jul2016'd ); putlog D4=;
run;
D1=0 wed-wed same day
D2=1 tue-wed one day
D3=2 mon-wed two days
D4=2 sun-wed still 2 days
Is it clearer now?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Intersting..It seems like what PG said below.. SAS treats Sat and Sun as 1 day..
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Is there a better function I can using so that Sat and Sun can be considered two days and to get the result I wanted, eg, how to make intck('WEEKDAY', '02jul2016'd , '05jul2016'd ) =1?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
How on earth do you find one day between the 2nd and the 5th?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Oh I think you want *work* days, not *week* days.
Maybe this will help https://communities.sas.com/t5/SAS-Procedures/INTCK-Holidays/td-p/48472
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
No, Chris..Actually I don't want to consider any holidays even July 4th.. I just want to count every day Mon - Fri, except Sat and Sun
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
WEEKDAY127W. would do it. But
days3=intck('WEEKDAY127W', '01jul2016'd , '05jul2016'd )
would also be = 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@PGStats I think he wants to ignore July 4th, not all Mondays 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I want to count July 4th as a work day.. so I am counting weekdays.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
So, instead of considering a start day in the weekend as a friday, you want to consider it as a monday. You want to count the boundaries between weekdays as if weekends did not exist. One way of achieving that is with a custom function, like this:
proc fcmp outlib=sasuser.fcmp.dates;
function weekdaydif(date1, date2);
return (intck("WEEKDAY", date1, date2) - (weekday(date1) in (1,7)));
endsub;
run;
options cmplib=sasuser.fcmp;
data _null_;
days1 = weekdaydif('02jul2016'd , '05jul2016'd);
days2 = weekdaydif('04jul2016'd , '07jul2016'd);
put days1= days2=;
run;
play with it to see if it does what you want.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
how would this work with timestamps on the dates?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I'd say SAS treats Sat and Sun as 0 day. Which is what you want if you choose the weekday interval.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
According to the documentation, intck with the WEEKDAY interval counts daily intervals with Friday-Saturday-Sunday counted as the same day. Thus the "weekdays" involved in the calculation of days1 are 1-2-3/4/5, where / indicates the counted boundaries.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
INTCK() counts the number of interval boundaries crossed. If you are counting WEEKDAYs then Saturday and Sunday don't count.
Fortunately you have a programming language at your fingertips you can use to see what it is doing.
Let's look at 7 days in March 2020, since it happens to start with the first day on a Sunday, which is the first day of the week.
data check;
do from='01MAR2020'd to '07MAR2020'd;
do days=0 to 8;
to=from+days;
weekdays = intck('weekday',from,to);
put from downame. '->' to downame. days 3. weekdays 3. ;
output;
end;
put;
end;
format from to date9. ;
run;
Results:
Sunday-> Sunday 0 0 Sunday-> Monday 1 1 Sunday-> Tuesday 2 2 Sunday->Wednesday 3 3 Sunday-> Thursday 4 4 Sunday-> Friday 5 5 Sunday-> Saturday 6 5 Sunday-> Sunday 7 5 Sunday-> Monday 8 6 Monday-> Monday 0 0 Monday-> Tuesday 1 1 Monday->Wednesday 2 2 Monday-> Thursday 3 3 Monday-> Friday 4 4 Monday-> Saturday 5 4 Monday-> Sunday 6 4 Monday-> Monday 7 5 Monday-> Tuesday 8 6 Tuesday-> Tuesday 0 0 Tuesday->Wednesday 1 1 Tuesday-> Thursday 2 2 Tuesday-> Friday 3 3 Tuesday-> Saturday 4 3 Tuesday-> Sunday 5 3 Tuesday-> Monday 6 4 Tuesday-> Tuesday 7 5 Tuesday->Wednesday 8 6 Wednesday->Wednesday 0 0 Wednesday-> Thursday 1 1 Wednesday-> Friday 2 2 Wednesday-> Saturday 3 2 Wednesday-> Sunday 4 2 Wednesday-> Monday 5 3 Wednesday-> Tuesday 6 4 Wednesday->Wednesday 7 5 Wednesday-> Thursday 8 6 Thursday-> Thursday 0 0 Thursday-> Friday 1 1 Thursday-> Saturday 2 1 Thursday-> Sunday 3 1 Thursday-> Monday 4 2 Thursday-> Tuesday 5 3 Thursday->Wednesday 6 4 Thursday-> Thursday 7 5 Thursday-> Friday 8 6 Friday-> Friday 0 0 Friday-> Saturday 1 0 Friday-> Sunday 2 0 Friday-> Monday 3 1 Friday-> Tuesday 4 2 Friday->Wednesday 5 3 Friday-> Thursday 6 4 Friday-> Friday 7 5 Friday-> Saturday 8 5 Saturday-> Saturday 0 0 Saturday-> Sunday 1 0 Saturday-> Monday 2 1 Saturday-> Tuesday 3 2 Saturday->Wednesday 4 3 Saturday-> Thursday 5 4 Saturday-> Friday 6 5 Saturday-> Saturday 7 5 Saturday-> Sunday 8 5
Which counts would you want to be different?
Perhaps you want count the number of weekdays between FROM and TO, inclusive? If so then see what you get if you use this formula instead:
intck('weekday',from-1,to)
Are these weekday counts what you want?
Sunday-> Sunday 0 0 Sunday-> Monday 1 1 Sunday-> Tuesday 2 2 Sunday->Wednesday 3 3 Sunday-> Thursday 4 4 Sunday-> Friday 5 5 Sunday-> Saturday 6 5 Sunday-> Sunday 7 5 Sunday-> Monday 8 6 Monday-> Monday 0 1 Monday-> Tuesday 1 2 Monday->Wednesday 2 3 Monday-> Thursday 3 4 Monday-> Friday 4 5 Monday-> Saturday 5 5 Monday-> Sunday 6 5 Monday-> Monday 7 6 Monday-> Tuesday 8 7 Tuesday-> Tuesday 0 1 Tuesday->Wednesday 1 2 Tuesday-> Thursday 2 3 Tuesday-> Friday 3 4 Tuesday-> Saturday 4 4 Tuesday-> Sunday 5 4 Tuesday-> Monday 6 5 Tuesday-> Tuesday 7 6 Tuesday->Wednesday 8 7 Wednesday->Wednesday 0 1 Wednesday-> Thursday 1 2 Wednesday-> Friday 2 3 Wednesday-> Saturday 3 3 Wednesday-> Sunday 4 3 Wednesday-> Monday 5 4 Wednesday-> Tuesday 6 5 Wednesday->Wednesday 7 6 Wednesday-> Thursday 8 7 Thursday-> Thursday 0 1 Thursday-> Friday 1 2 Thursday-> Saturday 2 2 Thursday-> Sunday 3 2 Thursday-> Monday 4 3 Thursday-> Tuesday 5 4 Thursday->Wednesday 6 5 Thursday-> Thursday 7 6 Thursday-> Friday 8 7 Friday-> Friday 0 1 Friday-> Saturday 1 1 Friday-> Sunday 2 1 Friday-> Monday 3 2 Friday-> Tuesday 4 3 Friday->Wednesday 5 4 Friday-> Thursday 6 5 Friday-> Friday 7 6 Friday-> Saturday 8 6 Saturday-> Saturday 0 0 Saturday-> Sunday 1 0 Saturday-> Monday 2 1 Saturday-> Tuesday 3 2 Saturday->Wednesday 4 3 Saturday-> Thursday 5 4 Saturday-> Friday 6 5 Saturday-> Saturday 7 5 Saturday-> Sunday 8 5