## I am trying to find out the number of working days in month using INTCK but getting incorrect result??

Occasional Contributor
Posts: 16

# I am trying to find out the number of working days in month using INTCK but getting incorrect result??

I am trying to find out the number of working days in month using INTCK but getting incorrect result??

I have used the below code, but it gives me correct result for one month but incorrect for other.

data kbc;

this_month_first_date=intnx('month',today(),0,'b');

next_month_first_date=intnx('month',today(),1,'b');

days=intck("weekday", this_month_first_date, next_month_first_date);

format this_month_first_date next_month_first_date date9.;

run;

proc print data=kbc;

run;

I have one doubt also that intnx function I used above is also counting the days: this_month_first_date, next_month_first_date + days between them for total numbers days in month. What I have studied is that intnx function calculates the time interval b/w two date/time value but it also include that two date/time is in doubts

Valued Guide
Posts: 864

## Re: I am trying to find out the number of working days in month using INTCK but getting incorrect result??

if you want to figure out number of days you would put 'day' not 'month'.  BUT, as I've seen pointed out in this forum before you only have to subtract date from date to get the difference in days, no function is necessary.   If this doesn't help give an example dataset and an example of what you want.

Super User
Posts: 13,556

## Re: I am trying to find out the number of working days in month using INTCK but getting incorrect result??

First would be to define what you mean by working days. Are holidays excluded? Which ones? Is the holiday actually observed on that date when it occurs on a Saturday or Sunday?

Note that there is a Holiday function for US and some Canadian holidays.

Posts: 4,736

## Re: I am trying to find out the number of working days in month using INTCK but getting incorrect result??

Is below what you're after?  SAS(R) 9.4 Language Reference: Concepts, Fourth Edition

data sample;

format start_dt end_dt date9.;

start_dt=intnx('month',today(),0,'b');

end_dt=intnx('month',start_dt,0,'e');

working_days=intck('WEEKDAY',start_dt,end_dt);

output;

stop;

run;

If you need to exclude holidays as well then you will likely have to create a custom interval. There have already been multiple discussions around this here in these forums so I suggest you do a search.

Super User
Posts: 3,919

## Re: I am trying to find out the number of working days in month using INTCK but getting incorrect result??

Try this. I think you have to set your start date as the last date of the previous month otherwise it is excluded from consideration, for example to get the correct number of calendar days in the month.

data _null_;

month = '01mar2015'd;

start = intnx('MONTH', month, -1, 'E');

end = intnx('MONTH',month, 0, 'E');

format month start end date9.;

weekdays = intck('WEEKDAY',start , end);

days = intck('DAY',start , end);

put _all_;

run;

Discussion stats
• 4 replies
• 1801 views
• 0 likes
• 5 in conversation