I thought the list might want to see the resolution to my issue. I wanted to
calculate the different between two times but wanted to drop the time on
weekends and holidays. Here is the syntax that works. I received several
helpful e-mails from the list although the syntax below was a variation of
Raynald's syntax. Thanks to all!
data list / date1 1-20 (DATETIME20) date2 22-41 (DATETIME20) .
18-JAN-2005 23:59:00 20-JAN-2005 00:01:00
01-JAN-2005 11:59:00 31-JAN-2005 18:00:00
15-DEC-2004 00:01:00 05-JAN-2005 23:59:00
04-JAN-2005 11:25:00 10-JAN-2005 12:35:00
01-JAN-2004 18:00:00 06-JAN-2004 18:00:00
25-DEC-2004 19:42:31 20-JAN-2005 14:34:25
*Just a baseline normal number of days* .
COMPUTE DAYS =CTIME.DAYS(date2-date1).
*Note dates are stored in seconds, 86400 per day*.
*Calculate the time until midnight on admitdate if it is not a weekend or
If RANGE(XDATE.WKDAY(date1),2,6) & ~ANY(XDATE.DATE(date1),
*Calculate the time since midnight on releasdate if it is not a weekend or
IF RANGE(XDATE.WKDAY(date2),2,6) &~ANY(XDATE.DATE(date2) ,
*Calculate the number of full days in between the admit and release date
that are not
holidays or weekends*.
LOOP #=(date1 + GAP1) to (date2 - ( 86400 + GAP2 )) BY 86400.
IF RANGE(XDATE.WKDAY(#),2,6) &~ANY(XDATE.DATE(#) ,
> Hello everyone,
> After a more thorough search and a few responses from listserv members, I
> found syntax that is almost exactly what I am looking for. The second data
> set that I spoke about in my first post now may be unnecessary. I pasted the
> syntax below and it is fro m Raynalds SPSS Tools<http://www.spsstools.net/SampleSyntax.htm#DatesAndTimes>. I changed the dummy data to my example and inserted a few 2005
> holidays. The syntax below is to find the number of elapsed weekdays in
> between two dates (see sample data) excluding public holidays but I would
> like to calculate the number of elapsed seconds in between two dates
> (01-JAN-2005 12:00:00 to 31-Jan-2005 18:00:00) excluding public holidays so
> that I can convert to hours, minutes, etc.
> Can anybody adjust the syntax below to account for this difference?
> The correct difference for the two dates I provided above should be
> 1,706,400 seconds or 19.75 days to account for the weekends as well as
> Martin Luther King Jr. Day on January 17th.
> If I use the data entered in DATETIME format as below, the syntax doesn't
> seem to account properly for the holiday i.e. with the ADATE format, the
> output is 20 days and with the DATETIME format, the output is 21 days :
> Thanks in advance to anyone who tries to help with this problem.
> data list / date1 1-20 (DATETIME20) date2 22-41 (DATETIME20) .
> begin data
> 01-JAN-2005 12:00:00 31-JAN-2005 18:00:00
> end data.
> * Here is a way to compute elapsed weekdays excluding Public Holidays *.
> * Raynald Levesque Summer 2002.
> data list / date1 1-10 (ADATE) date2 12-21 (ADATE) .
> begin data
> 01/01/2005 01/31/2005
> end data.
> * Just a baseline normal number of days* .
> COMPUTE DAYS =CTIME.DAYS(date2-date1).
> *Note dates are stored in seconds, 86400 per day * .
> COMPUTE WKDAYS=0.
> LOOP #=date1 to date2 BY 86400.
> * You have to add all applicable public holidays in next ANY command
> If RANGE(XDATE.WKDAY(#),2,6) & ~ANY(#,
> WKDAYS=WKDAYS +1.
> END LOOP.
> On 5/24/06, ariel barak <[hidden email] > wrote:
> > Fellow Subscribers,
> > Background and Goal: I am attempting to calculate a length of stay for
> > individuals sent to detention facilities excluding holiday and weekend days
> > for 2005.
> > Data: There are 2 data files. The first is about 10,000 admissions that
> > have variables titled AdmitDate and ReleaseDate both in dd-mmm-yyyy hh:mm:ss
> > format. This file is titled charges.sav. The second data file is a list
> > of the holiday and weekend days in 2004 and 2005 whose time should be
> > subtracted from the length of stay also in DATETIME20 format. This file
> > is titled excludeddays.sav.
> > Additional Complications: Although it may be easier to only create the
> > length of stay based on 2005 admissions, guidelines are to calculate the
> > length of stay for any individual in a detention facility during the 2005
> > calendar year. This means that I have to calculate the length of stay for
> > those who were admitted in 2004 and released in 2005.
> > Problem: I don't know how to exclude the holiday and weekend hours from
> > the length of stay.
> > How can I solve this problem? Any help would be greatly appreciated : )