Turn on suggestions

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

Showing results for

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

Options

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 10-22-2010 08:23 AM
(2990 views)

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

4 REPLIES 4

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

**Available on demand!**

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

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.