Calcite | Level 5

## Calculate the number of weekdays between two dates

Hi,

I need to calculate the number of week days (defined as Monday to Friday) between two dates and am unsure the best way to calculate this.

The date range can be between 1 day and 1,095.

Any advice would be greatly appreciated.

Regards,

Brian
4 REPLIES 4
SAS Super FREQ

## Re: Calculate the number of weekdays between two dates

Hi:
I'm not sure what you mean by a date range of "1 day and 1,095" -- do you mean the NUMBER of days between 2 dates can have that range but no more and no less or do you mean that the dates range from Jan 2, 1960 ( internal number value 1) to Dec 31, 1962 (1095 internal number value ).

Are your date variables numeric variables or character variables? If you run PROC CONTENTS on your SAS dataset you will be able to tell whether your date variables are character or numeric. It would also be useful to know whether your variables represent the number of DAYS since Jan 1, 1960 (simple date variables) or whether your variables represent the number of SECONDS since midnight on Jan 1, 1960 (a datetime variable).

cynthia
Lapis Lazuli | Level 10

## Re: Calculate the number of weekdays between two dates

From the SAS Language Dictionary documentation, have a look at using the DATA step function INTCK to count between two dates - weekday is handled with this function (coded as argument1 along with your two SAS DATE numeric variables).

Scott Barry
SBBWorks, Inc.

count weekdays intck function site:sas.com
Quartz | Level 8

## Re: Calculate the number of weekdays between two dates

Hello Brian,

This is an idea of a possible solution:

data a;
date1="01Oct2010"d;
date2="15Oct2010"d;
do date=date1 to date2;
if 2 le WEEKDAY(date) le 6 then count+1;
end;
format date date1 date2 date9.;
output;
run;

Sincerely,
SPR
Opal | Level 21

## Re: Calculate the number of weekdays between two dates

Hi Brian

As Scott suggested:

data _null_;
start='07jan2010'd;
do stop=start to '12jan2010'd;
wdvar=intck('weekday17w',start,stop);
put wdvar= @10 start= WEEKDATX. @50 stop= WEEKDATX. /;
end;
run;

HTH
Patrick
Discussion stats
• 4 replies
• 2991 views
• 1 like
• 5 in conversation