Date: Thu, 13 May 2010 09:23:09 -0400
Reply-To: Gene Maguin <emaguin@buffalo.edu>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: Gene Maguin <emaguin@buffalo.edu>
Subject: Re: Overlapping Periods
In-Reply-To: <E3E20F80689881429D0021DCA515EF5304F4411D@host.lodgenet.com>
Content-Type: text/plain; charset="us-ascii"
Jim,
Thank you for pointing out my error. The code I posted doesn't yield the
sample output. After studying Asil's imput and output this morning, I
realize that I didn't understand the problem that Asil had posed.
Gene Maguin
Gene:
The problem set includes overlapping and non-overlapping intervals--
case 3006 goes from three to one record, while case 30057 has three
non-overlapping intervals.
Asil:
Here is a solution.
** Sample data.
NEW FILE.
DATA LIST FREE/StudyID (f8.0) InDate (ADATE10) OutDate (ADATE10).
BEGIN DATA
30006 09/20/2002 04/30/2007
30006 12/29/2006 05/31/2012
30006 11/25/2009 05/31/2012
30014 04/16/1975 03/03/1988
30014 04/21/1980 05/28/1982
30014 02/16/2001 11/24/2001
30022 02/05/1992 07/22/1995
30057 02/01/1988 11/20/1988
30057 12/15/1989 10/17/1990
30057 01/23/1992 10/18/1993
END DATA.
DATASET NAME intervals WINDOW = FRONT.
** optional if live data is presorted.
SORT CASES BY studyID indate (A).
** Identify overlapping periods.
COMPUTE sequence = 1.
IF studyid = LAG(studyid) AND indate LE LAG(outdate) sequence =
LAG(sequence) + 1.
** create a variable to identify the start of a new overlapping period.
COMPUTE seq_start = sequence = 1.
** create a variable to number each new set of overlapping periods--
** needed to aggregate data.
FILTER BY seq_start.
RANK indate BY studyID / RANK INTO intervals.
FILTER OFF.
** transfer the number for each new overlapping period
** down to each case in the overlapping period.
NUMERIC #seq (F8.0).
DO IF seq_start.
. COMPUTE #seq = intervals.
ELSE .
. COMPUTE intervals = #seq.
END IF .
EXECUTE .
DATASET DECLARE final_data.
AGGREGATE OUTFILE = final_data /BREAK = studyID intervals
/indate = MIN(indate) /outdate = MAX(indate).
DATASET ACTIVATE final_data.
LIST.
Jim Marks
Director, Market Research
x1616
-----Original Message-----
From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] On Behalf Of
Gene Maguin
Sent: Wednesday, May 12, 2010 1:33 PM
To: SPSSX-L@LISTSERV.UGA.EDU
Subject: Re: Overlapping Periods
Asil,
I might be misunderstanding, but this looks like a straight forward
application of Aggregate where you select the min value of Indate and
the
max value of OutDate.
Gene Maguin
>>I would like to get the earliest in and latest out dates among a set
of
overlapping periods using syntax.
An example is provided below.
Could anyone help me with that?
Thanks,
Asil
EXAMPLE:
I would like to go from this set
StudyID InDate OutDate
30006 9/20/2002 4/30/2007
30006 12/29/2006 5/31/2012
30006 11/25/2009 5/31/2012
30014 4/16/1975 3/3/1988
30014 4/21/1980 5/28/1982
30014 2/16/2001 11/24/2001
30022 2/5/1992 7/22/1995
30057 2/1/1988 11/20/1988
30057 12/15/1989 10/17/1990
30057 1/23/1992 10/18/1993
To this set
StudyID InDate OutDate
30006 9/20/2002 5/31/2012
30014 4/16/1975 3/3/1988
30014 2/16/2001 11/24/2001
30022 2/5/1992 7/22/1995
30057 2/1/1988 11/20/1988
30057 12/15/1989 10/17/1990
30057 1/23/1992 10/18/1993
=====================
To manage your subscription to SPSSX-L, send a message to
LISTSERV@LISTSERV.UGA.EDU (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
=====================
To manage your subscription to SPSSX-L, send a message to
LISTSERV@LISTSERV.UGA.EDU (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
=====================
To manage your subscription to SPSSX-L, send a message to
LISTSERV@LISTSERV.UGA.EDU (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD