Contributor
Posts: 26

# How does intck weekdays work?

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

Super User
Posts: 2,499

## Re: How does intck weekdays work?

``````
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?

Contributor
Posts: 26

## Re: How does intck weekdays work?

Intersting..It seems like what PG said below.. SAS treats Sat and Sun as 1 day..

Contributor
Posts: 26

## Re: How does intck weekdays work?

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?

Super User
Posts: 2,499

## Re: How does intck weekdays work?

How on earth do you find one day between the 2nd and the 5th?

Super User
Posts: 2,499

## Re: How does intck weekdays work?

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

Contributor
Posts: 26

## Re: How does intck weekdays work?

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

Posts: 5,616

## Re: How does intck weekdays work?

WEEKDAY127W. would do it. But

days3=intck('WEEKDAY127W', '01jul2016'd , '05jul2016'd )

would also be = 1

PG
Super User
Posts: 2,499

## Re: How does intck weekdays work?

@PGStats I think he wants to ignore July 4th, not all Mondays

Contributor
Posts: 26

## Re: How does intck weekdays work?

I want to count July 4th as a work day.. so I am counting weekdays.

Posts: 5,616

## Re: How does intck weekdays work?

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.

PG
Super User
Posts: 2,499

## Re: How does intck weekdays work?

I'd say SAS treats Sat and Sun as 0 day. Which is what you want if you choose the weekday interval.