BookmarkSubscribeRSS Feed
Paari
Calcite | Level 5

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

4 REPLIES 4
Steelers_In_DC
Barite | Level 11

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.

ballardw
Super User

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.

Patrick
Opal | Level 21

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.

SASKiwi
PROC Star

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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