BookmarkSubscribeRSS Feed
Brian_lewis67
Calcite | Level 5
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
Cynthia_sas
SAS Super FREQ
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
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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
SPR
Quartz | Level 8 SPR
Quartz | Level 8
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
Patrick
Opal | Level 21
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

sas-innovate-2024.png

Available on demand!

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

 

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
  • 2991 views
  • 1 like
  • 5 in conversation