Identify Break in Service Use

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

Identify Break in Service Use

Doug Harden
Hi List

I need to calculate breaks in service use. My data is in the long format and
looks like this:

USEID Type SDate
4567     CD 1/1/2008
4567 CD 2/1/2008
4567 CD 3/1/2008
4567 CD 4/1/2008
4567 CD 5/1/2008
4567 CD 7/1/2009
4567 CD 8/1/2009
4567 CD 9/1/2009

The data is sorted by date. I want to determine if the length of time
between the service use date in one record and the service use date in
another record of the same ID is greater than 1 month. See the break between
5/1/2008 and 7/1/2009

I have a lot of records and I’m hoping there is syntax to help.

Thanks in advance.

DG

=====================
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: Identify Break in Service Use

David Marso
Administrator
See LAG and Datediff functions in the Syntax Reference and/or this list archives.

Doug Harden wrote
Hi List

I need to calculate breaks in service use. My data is in the long format and
looks like this:

USEID Type SDate
4567     CD 1/1/2008
4567 CD 2/1/2008
4567 CD 3/1/2008
4567 CD 4/1/2008
4567 CD 5/1/2008
4567 CD 7/1/2009
4567 CD 8/1/2009
4567 CD 9/1/2009

The data is sorted by date. I want to determine if the length of time
between the service use date in one record and the service use date in
another record of the same ID is greater than 1 month. See the break between
5/1/2008 and 7/1/2009

I have a lot of records and I’m hoping there is syntax to help.

Thanks in advance.

DG

=====================
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
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 Break in Service Use

Doug Harden
In reply to this post by Doug Harden
Thanks David,

I went on the list archives. I found the syntax and adapted it to my variables. But I have a follow up question.The syntax returns a very large and unusable number in the first instance of the date diff comparison. See the first instance of diff is 155307. How do I rewrite the syntax so it doesn't do that? The rest of the values makes sense. Anything greater than 31 is a value I can note as a noncontinuous value and flag it. 

Here is my syntax

COMPUTE Pdate = 0.
SORT CASES BY USEID Sdate (A).
IF (USEID  = lag(USEID,1)) PDate=lag(StartDate,1).
FORMATS PDate (DATE11).
COMPUTE diff=Datediff(Sdate,PDate,"Days").

Here is the outcome 

USEID TYPE Sdate diff
4567 4E 1/1/2008 155307
4567 4E 2/1/2008 31
4567 4E 3/1/2008 29
4567 4E 4/1/2008 31
4567 4E 5/1/2008 30
4567 4E 7/1/2009 426
4567 4E 8/1/2009 31
4567 4E 9/1/2009 31


From:        David Marso <[hidden email]>
To:        [hidden email]
Date:        04/17/2013 10:01 AM
Subject:        Re: Identify Break in Service Use
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




See LAG and Datediff functions in the Syntax Reference and/or this list
archives.


Doug Harden wrote
> Hi List
>
> I need to calculate breaks in service use. My data is in the long format
> and
> looks like this:
>
> USEID Type SDate
> 4567     CD 1/1/2008
> 4567 CD 2/1/2008
> 4567 CD 3/1/2008
> 4567 CD 4/1/2008
> 4567 CD 5/1/2008
> 4567 CD 7/1/2009
> 4567 CD 8/1/2009
> 4567 CD 9/1/2009
>
> The data is sorted by date. I want to determine if the length of time
> between the service use date in one record and the service use date in
> another record of the same ID is greater than 1 month. See the break
> between
> 5/1/2008 and 7/1/2009
>
> I have a lot of records and I’m hoping there is syntax to help.
>
> Thanks in advance.
>
> DG
>






Reply | Threaded
Open this post in threaded view
|

Re: Identify Break in Service Use

Art Kendall
try something like this. UNTESTED.
numeric diff (f5).
compute diff = -1.
missing values diff (-1).
SORT CASES BY USEID Sdate (A).
IF (USEID  eq lag(USEID,1)) diff =Datediff(Sdate,lag(sdate),"Days").
COMPUTE diff=Datediff(Sdate,PDate,"Days").
Art Kendall
Social Research Consultants
On 4/17/2013 5:47 PM, Doug Harden [via SPSSX Discussion] wrote:
Thanks David,

I went on the list archives. I found the syntax and adapted it to my variables. But I have a follow up question.The syntax returns a very large and unusable number in the first instance of the date diff comparison. See the first instance of diff is 155307. How do I rewrite the syntax so it doesn't do that? The rest of the values makes sense. Anything greater than 31 is a value I can note as a noncontinuous value and flag it. 

Here is my syntax

COMPUTE Pdate = 0.
SORT CASES BY USEID Sdate (A).
IF (USEID  = lag(USEID,1)) PDate=lag(StartDate,1).
FORMATS PDate (DATE11).
COMPUTE diff=Datediff(Sdate,PDate,"Days").

Here is the outcome 

USEID TYPE Sdate diff
4567 4E 1/1/2008 155307
4567 4E 2/1/2008 31
4567 4E 3/1/2008 29
4567 4E 4/1/2008 31
4567 4E 5/1/2008 30
4567 4E 7/1/2009 426
4567 4E 8/1/2009 31
4567 4E 9/1/2009 31


From:        David Marso <[hidden email]>
To:        [hidden email]
Date:        04/17/2013 10:01 AM
Subject:        Re: Identify Break in Service Use
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




See LAG and Datediff functions in the Syntax Reference and/or this list
archives.


Doug Harden wrote
> Hi List
>
> I need to calculate breaks in service use. My data is in the long format
> and
> looks like this:
>
> USEID Type SDate
> 4567     CD 1/1/2008
> 4567 CD 2/1/2008
> 4567 CD 3/1/2008
> 4567 CD 4/1/2008
> 4567 CD 5/1/2008
> 4567 CD 7/1/2009
> 4567 CD 8/1/2009
> 4567 CD 9/1/2009
>
> The data is sorted by date. I want to determine if the length of time
> between the service use date in one record and the service use date in
> another record of the same ID is greater than 1 month. See the break
> between
> 5/1/2008 and 7/1/2009
>
> I have a lot of records and I’m hoping there is syntax to help.
>
> Thanks in advance.
>
> DG
>









If you reply to this email, your message will be added to the discussion below:
http://spssx-discussion.1045642.n5.nabble.com/Identify-Break-in-Service-Use-tp5719525p5719531.html
To start a new topic under SPSSX Discussion, email [hidden email]
To unsubscribe from SPSSX Discussion, click here.
NAML

Art Kendall
Social Research Consultants