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 |
Administrator
|
See LAG and Datediff functions in the Syntax Reference and/or this list archives.
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?" |
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
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 > |
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 ConsultantsOn 4/17/2013 5:47 PM, Doug Harden [via SPSSX Discussion] wrote:
Art Kendall
Social Research Consultants |
Free forum by Nabble | Edit this page |