identify Min and Max Dates for Grouped Cases

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

identify Min and Max Dates for Grouped Cases

Kath Brookman
Hi, I need some further help with syntax I am writing. I’m sorry for the
lengthy explanation, but I’m trying to be clear.

Here is what I am trying to do. I have a file of treatment regimens with
sub-services that occur within the treatment regimen. And I want the minimum
and maximum date ranges of the whole of the treatment regimen episode, which
can include zero to many sub-services. Treatment episodes are differentiated
by time breaks. The services included within a treatment regimen are those
whose start date are less than a previous service end date. Any service can
lengthen the treatment regimen time range, resetting the calculation of
service start dates to service end dates.  As an example, I've included the
below syntax that reads in a snippet of the data I’m using with a do-loop
that identifies the start of a treatment regimen and identifies those
services that are within that whole treatment regimen.

A 0 indicates the start of a unique treatment regimen. The 1’s indicate that
those are services are within that treatment regimen. This can be
illustrated by ID 422 at Rank 7. The 0 indicates that this is a start of a
new treatment regimen for 422 because its start date is greater than any of
the previous services’ end dates.  Rank 8 is included in this treatment
regimen; however, the service at Rank 8 has an end date over three years
later than Rank 7’s end date, making all of the subsequent services (rank 9
and 10) within the treatment regimen because their start date is LT/= Rank
8’s end date which is less than Rank 7’s end date – thus resetting the end
date for that treatment regimen.  I really hope that wasn't a muddled
explanation.

Now, what I need. I want the minimum start and maximum end dates of the
whole treatment regimen period, but I don’t know how to identify them with
the syntax I am using. For 422, the first treatment regimen would have a
minstart of 8/22/2005 and a maxend date of 11/22/2006 for each case within
that treatment period. For 422, the second treatment regimen would have a
minstart of 12/19/2006 and a maxend of 6/23/2010 for each case within that
treatment regimen period. Here is my syntax. I don’t know how to pull over
the appropriate minimum and maximum dates into new variables (minstart) and
(maxend).

I really appreciate the help.

Kath

DATA LIST list / ID(F1.0) Rank(F1.0) start(ADATE) end(ADATE)
minstartdate(ADATE) maxenddate(ADATE).
BEGIN DATA
422 1 8/22/2005 10/3/2006
422 2 8/23/2005 9/12/2005
422 3 8/23/2005 10/3/2006
422 4 8/23/2005 10/3/2006
422 5 3/24/2006 9/15/2006
422 6 3/27/2006 11/22/2006
422 7 12/19/2006 1/9/2007
422 8 12/20/2006 6/23/2010
422 9 2/28/2008 7/29/2008
422 10 2/28/2008 10/10/2008
468 1 8/7/2006 4/27/2007
468 2 8/9/2006 9/5/2006
468 3 10/16/2006 10/17/2006
468 4 7/19/2007 7/23/2007
468 5 7/20/2007 12/24/2007
468 6 7/24/2007 8/6/2007
468 7 4/15/2008 5/28/2008
468 8 4/17/2008 3/5/2009
468 9 9/29/2008 11/10/2008
671 1 4/26/2006 10/30/2006
671 2 5/1/2006 6/12/2006
671 3 1/16/2007 6/30/2008
671 4 1/18/2007 6/18/2007
671 5 7/25/2007 8/27/2007
671 6 8/26/2008 10/6/2008
671 7 4/14/2009 10/26/2009
671 8 11/10/2009 12/21/2009
671 9 10/27/2010 7/11/2011
end data.

compute flag = $sysmis.
LOOP numvar=1 TO 10.
 DO IF id = lag(id) AND start <= lag(end).
 COMPUTE flag=1.
ELSE.
COMPUTE flag=0.
END IF.
END LOOP.
EXECUTE.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (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
Reply | Threaded
Open this post in threaded view
|

Identify Min/Max Dates for Group Cases

Kath Brookman
So sorry for multiple postings. I kept getting error messages when I sent the email and I thought that meant the email was not posting to the list.

Kath
Reply | Threaded
Open this post in threaded view
|

Re: identify Min and Max Dates for Grouped Cases

David Marso
Administrator
In reply to this post by Kath Brookman
First, please post once and wait for people to reply rather than 4 times?
I believe this solves the riddle.
DO IF $CASENUM=1 OR id NE LAG(ID).
+  COMPUTE #maxend=end.
+  COMPUTE sameepisode=1.
+  COMPUTE episode=1.
ELSE.
+  COMPUTE sameepisode=  ((id EQ LAG(id)) AND range(start,lag(start),#maxend)).
+  COMPUTE #maxend=MAX(end,#maxend).
+  IF sameepisode episode=LAG(episode).
+  IF NOT(sameepisode) episode=LAG(episode) + 1.
END IF.
LIST.
AGGREGATE OUTFILE * MODE ADDVARIABLES
  / BREAK ID episode
  / minstartdate =MIN(start)
  / maxenddate   =MAX(end).
LIST.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: identify Min and Max Dates for Grouped Cases

David Marso
Administrator
That one can be refined a bit:

DO IF $CASENUM=1 OR id NE LAG(ID).
+  COMPUTE episode=1.
+  COMPUTE #maxend=end.
ELSE.
+  COMPUTE episode=LAG(episode) + NOT((RANGE(start,lag(start),#maxend))).
+  COMPUTE #maxend=MAX(end,#maxend).
END IF.


David Marso wrote
First, please post once and wait for people to reply rather than 4 times?
I believe this solves the riddle.
DO IF $CASENUM=1 OR id NE LAG(ID).
+  COMPUTE #maxend=end.
+  COMPUTE sameepisode=1.
+  COMPUTE episode=1.
ELSE.
+  COMPUTE sameepisode=  ((id EQ LAG(id)) AND range(start,lag(start),#maxend)).
+  COMPUTE #maxend=MAX(end,#maxend).
+  IF sameepisode episode=LAG(episode).
+  IF NOT(sameepisode) episode=LAG(episode) + 1.
END IF.
LIST.
AGGREGATE OUTFILE * MODE ADDVARIABLES
  / BREAK ID episode
  / minstartdate =MIN(start)
  / maxenddate   =MAX(end).
LIST.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: identify Min and Max Dates for Grouped Cases

Kath Brookman
In reply to this post by Kath Brookman
David,

Thanks, this is exactly what I needed. I am sorry about the multiple posts. I am really embarrassed about it. I received error messages from Yahoo and it was about an hour before for my message(s) were posted - which I interpreted as the messages not being posted and would try again.

Thanks again.

Kath


That one can be refined a bit:
 
DO IF $CASENUM=1 OR id NE LAG(ID).
+  COMPUTE episode=1.
+  COMPUTE #maxend=end.
ELSE.
+  COMPUTE episode=LAG(episode) + NOT((RANGE(start,lag(start),#maxend))).
+  COMPUTE #maxend=MAX(end,#maxend).
END IF.
 
 
 
David Marso wrote
> First, please post once and wait for people to reply rather than 4 times?
> I believe this solves the riddle.
> DO IF $CASENUM=1 OR id NE LAG(ID).
> +  COMPUTE #maxend=end.
> +  COMPUTE sameepisode=1.
> +  COMPUTE episode=1.
> ELSE.
> +  COMPUTE sameepisode=  ((id EQ LAG(id)) AND
> range(start,lag(start),#maxend)).
> +  COMPUTE #maxend=MAX(end,#maxend).
> +  IF sameepisode episode=LAG(episode).
> +  IF NOT(sameepisode) episode=LAG(episode) + 1.
> END IF.
> LIST.
> AGGREGATE OUTFILE * MODE ADDVARIABLES
>   / BREAK ID episode
>   / minstartdate =MIN(start)
>   / maxenddate   =MAX(end).
> LIST.