Date: Thu, 6 Sep 2007 09:28:59 -0500
Reply-To: Melissa Ives <mives@chestnut.org>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: Melissa Ives <mives@chestnut.org>
Subject: Re: seeking help in calculating number of days
Content-Type: text/plain; charset="us-ascii"
An alternative (if you have an older version of SPSS that doesn't do
MODE=ADDVARIABLES would be to
Sort cases by personcni intimidationdate (D).
If (personcni=lag(personcni)) intimidationdate=lag(intimidationdate).
By sorting in descending order, the blank intimidationdate values will
sort after the valid intimidationdate value.
The lag function will then copy the valid intimidationdate value down to
the blank rows for the same personcni.
Melissa
-----Original Message-----
From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] On Behalf Of
Richard Ristow
Sent: Thursday, September 06, 2007 7:23 AM
To: SPSSX-L@LISTSERV.UGA.EDU
Subject: Re: [SPSSX-L] seeking help in calculating number of days
At 01:55 AM 9/6/2007, Thara Vardhan wrote:
>I would be grateful if anyone could help me calculate the number of
>days between the 2 dates - "Eventdate" and "Intimidation date".
|-----------------------------|---------------------------|
|Output Created |06-SEP-2007 08:14:19 |
|-----------------------------|---------------------------|
Personcni eventdate intimidationdate
xyz 13-APR-2004 13-APR-2004
abc 06-JUN-2006 06-JUN-2006
hij 22-JUL-2003 .
hij 22-JUL-2003 .
hij 23-NOV-2003 .
hij 27-NOV-2004 .
hij 24-OCT-2005 24-OCT-2005
hij 17-MAR-2006 .
hij 17-MAR-2006 .
lop 01-OCT-2005 .
lop 14-DEC-2005 .
lop 08-APR-2006 08-APR-2006
efg 06-SEP-2005 .
efg 06-SEP-2005 06-SEP-2005
aks 05-FEB-2005 .
aks 05-FEB-2005 05-FEB-2005
aks 19-APR-2005 .
stu 27-APR-2004 27-APR-2004
stu 27-FEB-2006 .
stu 02-NOV-2003 02-NOV-2003
Number of cases read: 20 Number of cases listed: 20
>I have tried using the date diff function and it works but it only
>calculates where there are values in the two columns.
Right. That's true of any transformation that doesn't explicitly deal
with multiple cases. DateDiff has no notion that there's any value
except in the immediate record it's looking at.
>What I need to calculate is the number of days between each eventdate
>and intimidationdate for each personcni.
It looks like a person ('Personcni') has one 'intimidationdate' and any
number of 'eventdate' values. You need to get the 'intimidationdate'
value into *all* the person's records; then, DateDiff will work. Like
this - SPSS 15 draft output (WRR:not saved separately):
AGGREGATE OUTFILE=* MODE=ADDVARIABLES OVERWRITE=YES
/BREAK=Personcni
/intimidationdate = MAX(intimidationdate).
LIST.
List
|-----------------------------|---------------------------|
|Output Created |06-SEP-2007 08:18:01 |
|-----------------------------|---------------------------|
Personcni eventdate intimidationdate
xyz 13-APR-2004 13-APR-2004
abc 06-JUN-2006 06-JUN-2006
hij 22-JUL-2003 24-OCT-2005
hij 22-JUL-2003 24-OCT-2005
hij 23-NOV-2003 24-OCT-2005
hij 27-NOV-2004 24-OCT-2005
hij 24-OCT-2005 24-OCT-2005
hij 17-MAR-2006 24-OCT-2005
hij 17-MAR-2006 24-OCT-2005
lop 01-OCT-2005 08-APR-2006
lop 14-DEC-2005 08-APR-2006
lop 08-APR-2006 08-APR-2006
efg 06-SEP-2005 06-SEP-2005
efg 06-SEP-2005 06-SEP-2005
aks 05-FEB-2005 05-FEB-2005
aks 05-FEB-2005 05-FEB-2005
aks 19-APR-2005 05-FEB-2005
stu 27-APR-2004 27-APR-2004
stu 27-FEB-2006 27-APR-2004
stu 02-NOV-2003 27-APR-2004
Number of cases read: 20 Number of cases listed: 20
===================
APPENDIX: Test data
===================
(Works, but gives many warning messages)
DATA LIST LIST SKIP=2
/Personcni eventdate intimidationdate
(A3, DATE11, DATE11).
BEGIN DATA
Personcni eventdate intimidationdate
----|---10----|---20----|---30----|---40----|---50----|---60----|
xyz 13-APR-2004 13-APR-2004
abc 06-JUN-2006 06-JUN-2006
hij 22-JUL-2003 .
hij 22-JUL-2003 .
hij 23-NOV-2003 .
hij 27-NOV-2004 .
hij 24-OCT-2005 24-OCT-2005
hij 17-MAR-2006 .
hij 17-MAR-2006 .
lop 01-OCT-2005 .
lop 14-DEC-2005 .
lop 08-APR-2006 08-APR-2006
efg 06-SEP-2005 .
efg 06-SEP-2005 06-SEP-2005
aks 05-FEB-2005 .
aks 05-FEB-2005 05-FEB-2005
aks 19-APR-2005 .
stu 27-APR-2004 27-APR-2004
stu 27-FEB-2006 .
stu 02-NOV-2003 02-NOV-2003
END DATA.
LIST.
PRIVILEGED AND CONFIDENTIAL INFORMATION
This transmittal and any attachments may contain PRIVILEGED AND
CONFIDENTIAL information and is intended only for the use of the
addressee. If you are not the designated recipient, or an employee
or agent authorized to deliver such transmittals to the designated
recipient, you are hereby notified that any dissemination,
copying or publication of this transmittal is strictly prohibited. If
you have received this transmittal in error, please notify us
immediately by replying to the sender and delete this copy from your
system. You may also call us at (309) 827-6026 for assistance.