From: R.A.Reese@SEQUENT.CC.HULL.AC.UK (Allan Reese)
Newsgroups: bit.listserv.spssx-l
Subject: Days and working days.
Date: 13 Oct 92 15:11:09 GMT
Reply-To: Allan Reese <R.A.Reese@SEQUENT.CC.HULL.AC.UK>
Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU
Via: uk.ac.hull.cc.sequent; Tue, 13 Oct 1992 16:09:36 +0100
X-Mailer: ELM [version 2.3 PL11]
Original-Sender: R.A.Reese@sequent.cc.hull.ac.uk
Comments: To: "(SPSSX-L list)" <spssx-l@uga.cc.uga.edu>

Do you remember the wall plaques they sell in novelty shops, that
start with the population of the country, subtract the unemployed,
those in prison, those in hospital etc etc, to arrive at the
conclusion that there's only you and me to do all the work?

That came to mind when I was asked how to compute the number of days
between two dates (easy), which then turned into the number of
WORKING days between two dates.  It also needed to be in SPSS PC+,
which means the WKDAY function isn't available. I hacked the following.
It may be of general use, or if anyone spots an error in it I'd like
to know.

The example shown uses two dates, for "case referred" and "results received".
They happened to be in the same year for every case.


title 'Calculate elapsed days AND working days between dates.'.
* We will need to know some strange numbers, one for each bank holiday.
* The following commands put these numbers into the output window, so they
* can be patched into commands by editing.
data list free / yr mo da  name(a12).
compute d=yrmoda(yr,mo,da).
formats yr to da d(f10.0).
begin data.
92 12 25 'Christmas'
91 12 25 'Christmas'
92 4 19  'Easter'
92 5 3   'Mayday'
92 5 25  'Spring bank'
end data.
list.

get file='liz2.sys'
 /keep= YEAR DAYREF MONREF DAYREC MONREC ID.
* Turn each date into number of days since 14 October 1582.
compute ref=yrmoda(year,monref,dayref).
compute rec=yrmoda(year,monrec,dayrec).
* Elapsed days is just the difference.
compute lapse=rec-ref.
* Find WKDAY function for each date. The .5s are to avoid rounding problems.
compute dref=(ref-2)-7*trunc((ref-2.5)/7).
compute drec=(rec-2)-7*trunc((rec-2.5)/7).
* Remove weekends from full weeks.
compute workday=lapse-2*trunc((lapse+.5)/7).
* Adjust for weekend in last part-week using day numbers.
if (drec<dref) workday=workday-2.
* Adjust for any possibly intervening bank holidays. These are calculated
* as absolute numbers above to avoid putting, e.g., yrmoda(92,4,19) to be
* calculated twice for every case.
* This first line adjusts for Good Friday and Easter Monday 1992.
if (dref<149572 and drec>149572) workday=workday-2.
* Next Mayday, then Spring Bank holiday.
if (dref<149586 and drec>149586) workday=workday-1.
if (dref<149608 and drec>149608) workday=workday-1.
* The country closes down between Christmas and New Year.
if (dref<149456 and drec>149456) workday=workday-6.
formats year to monrec (f4.0) id(f3.0) rec ref (f8.0) lapse workday(f3.0).
value labels monrec monref 3 'March' 4 'April' 5 'May' 6 'June' 7 'July'
         8 'Aug' 9 'Sept'.
value labels dref drec 1 'Sun' 2 'Mon' 3 'Tue' 4 'Wed' 5 'Thu' 6 'Fri' 7 'Sat'.
report / format=list(5)
     / variables=year(4) dayrec(6) monrec(label)(6) drec(label)(4)
                         dayref(7) monref(label)(7) dref(label)(4)
                 lapse(7) workday(7).
fre var dref drec.
* That showed some work apparently on Sat or Sunday - can't have that!
compute query=(dref=1 or dref=7 or drec=1 or drec=7).
process if (query=1).
list.



--
(R.) Allan Reese        Janet:          r.a.reese@uk.ac.hull
Head of Applications    Direct voice:   +44 482 465296
Computer Centre         Voice messages: +44 482 465685
Hull University         Fax:            +44 482 466441
Hull HU6 7RX, U.K.
Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU