turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- Calculate the number of weekdays between two dates

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

10-22-2010 08:23 AM

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

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

10-22-2010 08:54 AM

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

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

10-22-2010 10:32 AM

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.

Suggested Google advanced search argument, this topic / post:

count weekdays intck function site:sas.com

Scott Barry

SBBWorks, Inc.

Suggested Google advanced search argument, this topic / post:

count weekdays intck function site:sas.com

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

10-22-2010 10:40 AM

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

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

10-22-2010 08:59 PM

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

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