Date: Mon, 10 Jun 1996 17:37:57 GMT "Glenn H. Itano" "SAS(r) Discussion" "Glenn H. Itano" Pomoxis Systems Re: # of weekdays between two SAS dates

One more way to do this - 6.07 or later, I think

>In article <1bc33370@am.pnu.com>, <GSDIMENT@AM.PNU.COM> wrote: >>A colleague of mine wonders if there is code out there to calculate the >>number of weekdays between two SAS dates. For his purposes, weekdays are >>all days Mon-Fri. In other words, the # of weekdays between two dates >>would be the number of days, minus all Saturdays & Sundays. ...

Use the "weekday" interval with the INTCK function -

weekdays = intck("WEEKDAY",date1,date2);

Note that if date1=date2, this returns a 0. If you want to calculate the number of weekdays between two dates inclusive, you should use

weekdays = 1 + intck("weekday",date1,date2);

I ought to rtfm (or tech report or online help) a bit more often...

You might use the code I posted earlier,

> weekdays = 1 + date2 - date1 /* If start=end, get 1 work day */ > - 2*intck("week",date1,date2) /* subtract 2* #weekends */ > - (weekday(date1)=1) /* subtract 1 if date1 is Sunday */ > - (weekday(date2)=7) /* subtract 1 if date2 is Saturday */ > ;

if you're using an earler version of SAS (pre-6.07).

Glenn

-- +----------------+------------------+-----------------+---------------------+ | Glenn H. Itano | itano@netcom.com | Pomoxis Systems | Alameda, California | +----------------+------------------+-----------------+---------------------+

Back to: Top of message | Previous page | Main SAS-L page