Count # of Events Within an Episode

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

Count # of Events Within an Episode

ariel barak
Hello All,

I have what I assume is a relatively easy task. I'm trying to test
whether an event has happened during an episode. All dates are in
proper SPSS date formats. Here is some sample data:


DATA LIST LIST /PatientID (A6) EpisodeID (F8) Start_Date (ADATE)
EndDate (ADATE) Event_Date.1 (ADATE) Event_Date.2 (ADATE) Event_Date.3
(ADATE) Event_Date.4 (ADATE).
BEGIN DATA
012345 1 12/23/2008 06/24/2009 11/18/2008 07/01/2009
067890 2 02/05/2009 08/05/2009 04/04/2009
067890 1 05/08/2006 11/08/2007 05/15/2006 08/08/2006 01/01/2007
END DATA.
DATASET NAME OriginalData.


My actual dataset has event dates from Event_Date.1 to Event_Date.34.
What I would like to do is to create a variable called
EventsDuringEpisode that counts the number of times there is an
Event_Date that occurs within the Start_Date and End_Date of the
episode. The data above would result in: 0, 1, and 3 for the three
records above.

Thanks in advance,
Ari

=====================
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
|

Re: Count # of Events Within an Episode

Ruben Geert van den Berg
Dear Ariel,

If I understand correctly, you can modify the syntax below for 34 date variables. 

Best regards,

Ruben van den Berg

Methodologist

TNS NIPO

E: [hidden email]

P: +31 20 522 5738

I: www.tns-nipo.com


DATA LIST LIST /PatientID (A6) EpisodeID (F8) Start_Date (ADATE)
EndDate (ADATE) Event_Date.1 (ADATE) Event_Date.2 (ADATE) Event_Date.3
(ADATE) Event_Date.4 (ADATE).
BEGIN DATA
012345 1 12/23/2008 06/24/2009 11/18/2008 07/01/2009
067890 2 02/05/2009 08/05/2009 04/04/2009
067890 1 05/08/2006 11/08/2007 05/15/2006 08/08/2006 01/01/2007
END DATA.
DATASET NAME D1.

comp EventsDuringEpisode=0.
vector bla=Event_Date.1 to Event_Date.4.
loop #i=1 to 4.
if bla(#i) ge Start_Date and bla(#i) le EndDate EventsDuringEpisode=EventsDuringEpisode+1.
end loop.
exe.



> Date: Wed, 14 Apr 2010 12:43:49 -0500
> From: [hidden email]
> Subject: Count # of Events Within an Episode
> To: [hidden email]
>
> Hello All,
>
> I have what I assume is a relatively easy task. I'm trying to test
> whether an event has happened during an episode. All dates are in
> proper SPSS date formats. Here is some sample data:
>
>
> DATA LIST LIST /PatientID (A6) EpisodeID (F8) Start_Date (ADATE)
> EndDate (ADATE) Event_Date.1 (ADATE) Event_Date.2 (ADATE) Event_Date.3
> (ADATE) Event_Date.4 (ADATE).
> BEGIN DATA
> 012345 1 12/23/2008 06/24/2009 11/18/2008 07/01/2009
> 067890 2 02/05/2009 08/05/2009 04/04/2009
> 067890 1 05/08/2006 11/08/2007 05/15/2006 08/08/2006 01/01/2007
> END DATA.
> DATASET NAME OriginalData.
>
>
> My actual dataset has event dates from Event_Date.1 to Event_Date.34.
> What I would like to do is to create a variable called
> EventsDuringEpisode that counts the number of times there is an
> Event_Date that occurs within the Start_Date and End_Date of the
> episode. The data above would result in: 0, 1, and 3 for the three
> records above.
>
> Thanks in advance,
> Ari
>
> =====================
> 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


Express yourself instantly with MSN Messenger! MSN Messenger
Reply | Threaded
Open this post in threaded view
|

Re: Count # of Events Within an Episode

Maguin, Eugene
In reply to this post by ariel barak
Ari,

Yes, this is pretty easy to do. One method uses a Loop-end loop structure
and the other uses a Do repeat structure.

**** Loop-end loop method.
Vector event=Event_Date.1 to Event_Date.34.
Compute nevents=0.
Loop #i=1 to 34.
+  do if (not(sysmis(event(#i)))).
+     if (start_date lt event(#i) and event(#i) le stop_date)
nevents=nevents+1.
+  else.
+     break.  /* jumps out of loop if sysmis eventdate.
+  end if.
End loop.


**** do repeat method.
Compute nevents=0.
Do repeat x=Event_Date.1 to Event_Date.34.
+  do if (not(sysmis(x))).
+     if (start_date lt x and x le stop_date) nevents=nevents+1.
+  end if.
End repeat.





>>I have what I assume is a relatively easy task. I'm trying to test
whether an event has happened during an episode. All dates are in
proper SPSS date formats. Here is some sample data:


DATA LIST LIST /PatientID (A6) EpisodeID (F8) Start_Date (ADATE)
EndDate (ADATE) Event_Date.1 (ADATE) Event_Date.2 (ADATE) Event_Date.3
(ADATE) Event_Date.4 (ADATE).
BEGIN DATA
012345 1 12/23/2008 06/24/2009 11/18/2008 07/01/2009
067890 2 02/05/2009 08/05/2009 04/04/2009
067890 1 05/08/2006 11/08/2007 05/15/2006 08/08/2006 01/01/2007
END DATA.
DATASET NAME OriginalData.


My actual dataset has event dates from Event_Date.1 to Event_Date.34.
What I would like to do is to create a variable called
EventsDuringEpisode that counts the number of times there is an
Event_Date that occurs within the Start_Date and End_Date of the
episode. The data above would result in: 0, 1, and 3 for the three
records above.

Thanks in advance,
Ari

=====================
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
|

Re: Count # of Events Within an Episode

ariel barak
The syntax works..thanks Gene and Ruben! I appreciate it.

-Ari

On Wed, Apr 14, 2010 at 1:37 PM, Gene Maguin <[hidden email]> wrote:

> Ari,
>
> Yes, this is pretty easy to do. One method uses a Loop-end loop structure
> and the other uses a Do repeat structure.
>
> **** Loop-end loop method.
> Vector event=Event_Date.1 to Event_Date.34.
> Compute nevents=0.
> Loop #i=1 to 34.
> +  do if (not(sysmis(event(#i)))).
> +     if (start_date lt event(#i) and event(#i) le stop_date)
> nevents=nevents+1.
> +  else.
> +     break.  /* jumps out of loop if sysmis eventdate.
> +  end if.
> End loop.
>
>
> **** do repeat method.
> Compute nevents=0.
> Do repeat x=Event_Date.1 to Event_Date.34.
> +  do if (not(sysmis(x))).
> +     if (start_date lt x and x le stop_date) nevents=nevents+1.
> +  end if.
> End repeat.
>
>
>
>
>
>>>I have what I assume is a relatively easy task. I'm trying to test
> whether an event has happened during an episode. All dates are in
> proper SPSS date formats. Here is some sample data:
>
>
> DATA LIST LIST /PatientID (A6) EpisodeID (F8) Start_Date (ADATE)
> EndDate (ADATE) Event_Date.1 (ADATE) Event_Date.2 (ADATE) Event_Date.3
> (ADATE) Event_Date.4 (ADATE).
> BEGIN DATA
> 012345 1 12/23/2008 06/24/2009 11/18/2008 07/01/2009
> 067890 2 02/05/2009 08/05/2009 04/04/2009
> 067890 1 05/08/2006 11/08/2007 05/15/2006 08/08/2006 01/01/2007
> END DATA.
> DATASET NAME OriginalData.
>
>
> My actual dataset has event dates from Event_Date.1 to Event_Date.34.
> What I would like to do is to create a variable called
> EventsDuringEpisode that counts the number of times there is an
> Event_Date that occurs within the Start_Date and End_Date of the
> episode. The data above would result in: 0, 1, and 3 for the three
> records above.
>
> Thanks in advance,
> Ari
>
> =====================
> 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
>

=====================
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
|

Re: Count # of Events Within an Episode

Richard Ristow
In reply to this post by ariel barak
At 01:43 PM 4/14/2010, Ariel Barak wrote:

I'm trying to test whether an event has happened during an episode. Here is some sample data:
|-----------------------------|---------------------------|
|Output Created               |16-APR-2010 20:54:09       |
|-----------------------------|---------------------------|
[OriginalData]
PtntID EpsID Start_Date    EndDate Evt_Date.1 Evt_Date.2 Evt_Date.3 Evt_Date.4

012345    1  12/23/2008 06/24/2009 11/18/2008 07/01/2009          .          .
067890    2  02/05/2009 08/05/2009 04/04/2009          .          .          .
067890    1  05/08/2006 11/08/2007 05/15/2006 08/08/2006 01/01/2007          .

Number of cases read:  3    Number of cases listed:  3


I would like to create a variable called EventsDuringEpisode that counts the number of Event_Date times that occur within the Start_Date and End_Date of the episode. The data above would result in: 0, 1, and 3 for the three [episodes].

You have solutions, including the neat two by Gene Maguin.

I note that your variables Event_Date.1 TO Event_Date.4 have the form you'd get starting with a long-form dataset, with one event date per record, and rolling it up using CASESTOVARS. If so, it looks like that would have been a laborious job, especially to ensure all event dates that could be for an episode, are on the record for that episode.

There are solutions that work with long-form data directly, and possibly one of those would be easier overall.

-Best of luck to you,
 Richard

===================
APPENDIX: Test data
===================
Test data as posted, with LIST to wrap lines logically
------------------------------------------------------
DATA LIST LIST /PatientID (A6) EpisodeID (F8) Start_Date (ADATE)
EndDate (ADATE) Event_Date.1 (ADATE) Event_Date.2 (ADATE) Event_Date.3
(ADATE) Event_Date.4 (ADATE).
BEGIN DATA
012345 1 12/23/2008 06/24/2009 11/18/2008 07/01/2009
067890 2 02/05/2009 08/05/2009 04/04/2009
067890 1 05/08/2006 11/08/2007 05/15/2006 08/08/2006 01/01/2007
END DATA.
DATASET NAME OriginalData.

TEMPORARY.
STRING SPACE(A20).
LIST PatientID    TO EndDate    SPACE
     Event_Date.1 TO Event_Date.4.
-----------------------------------------------------
With shorter variable names, so listing's on one line
-----------------------------------------------------
DATA LIST LIST /PtntID (A6) EpsID (F2) Start_Date (ADATE)
EndDate (ADATE) Evt_Date.1 (ADATE) Evt_Date.2 (ADATE) Evt_Date.3
(ADATE) Evt_Date.4 (ADATE).
BEGIN DATA
012345 1 12/23/2008 06/24/2009 11/18/2008 07/01/2009
067890 2 02/05/2009 08/05/2009 04/04/2009
067890 1 05/08/2006 11/08/2007 05/15/2006 08/08/2006 01/01/2007
END DATA.
DATASET NAME OriginalData.
LIST.

===================== 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