Date: Fri, 19 May 2006 10:27:36 +0930
Reply-To: "Barnett, Adrian (HEALTH)" <adrian.barnett@HEALTH.SA.GOV.AU>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: "Barnett, Adrian (HEALTH)" <adrian.barnett@HEALTH.SA.GOV.AU>
Subject: Re: help with dates and multiple enteries per subjects
Content-Type: text/plain; charset="us-ascii"
Hi Shirley
For this you need to make use of 2 functions, lag, which allows you to
refer to the case before the current one, and the datediff function,
which calculates the difference between two dates and expresses it in
whichever units you want, out of years, quarters, months, weeks, days,
hours, minutes or seconds. (p79 Version 14 syntax guide).
Below is a description of the logic, then under that is some code which
implements it.
First sort your data in ascending order of ID and discharge date.
Then, for cases in which the current ID is the same as the one of the
record before (i.e., people who have more than one admission record),
calculate the difference between the current admission date and the
PREVIOUS discharge date (expressing it in whichever units are best for
your purpose). If you want units smaller than days you will need to
have your date data recorded as a date+time data type, in which the time
of day is appended to the date.
Below is an untested example of code you might use to achieve this.
Sort cases ID DISCHARGE.
Do if (ID eq lag(ID)).
- compute INTERVAL = datediff(ADMISSION,lag(DISCHARGE),"days").
End if.
If you've only got your date variables as the pure date (i.e. time was
not also recorded), anyone who had more than one admission on the same
day will of course have a value of zero for INTERVAL.
Regards
Adrian
--
Adrian Barnett
Research & Information Officer Ph: +61 8 82266615
Research, Analysis and Evaluation Fax: +61 8
82267088
Strategic Planning and Research Branch
Strategic Planning and Population Health Division
Department of Health
God is good but don't dance in a currach. - Irish proverb
This e-mail may contain confidential information, which also may be
legally privileged. Only the intended recipient(s) may access, use,
distribute or copy this e-mail. If this e-mail is received in error,
please inform the sender by return e-mail and delete the original. If
there are doubts about the validity of this message, please contact the
sender by telephone. It is the recipient's responsibility to check the
e-mail and any attached files for viruses.
-----Original Message-----
From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] On Behalf Of
Shirli Werner
Sent: Friday, 19 May 2006 12:37
To: SPSSX-L@LISTSERV.UGA.EDU
Subject: help with dates and multiple enteries per subjects
Hello to all the SPSS experts,
I have a dataset in which each subject can have multiple enteries on
hospital admission and discharges. For example:
ID admission date discharge date
1 12.3.76 12.4.77
1 11.4.78 12.4.79
2 9.3.88 9.10.88
I would like to be able to calculate the time that has passed between
admission. That is, the time between one discharge date and the next
admission date for each subject (where some subjects might have had only
one admission and others several admissions).
Any help on this issue would be greatly appreciated.
Shirli