Calculate date difference based on conditions -nested IDs

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

Calculate date difference based on conditions -nested IDs

Tamra Boyce
I have a file with 5,000 or so cases.  All cases have two id’s, a unique
client id and an agency id.  Each client may have multiple agency visits
with multiple entrance and release dates.  For example, the dataset can
look like this:

ClientID       AgencyID       EntranceDate ReleaseDate
559       AL  9/6/2007 9/14/2007
604       AW  9/7/2007 1/18/2008
604      BU  1/28/2008 6/1/2008
673       BY  9/6/2007 12/18/2008
673       BY  1/28/2008 2/12/2008
673      EK  2/13/2008 6/1/2008

First, I need to calculate the date difference between the very last
release date and the very first entrance date by ID.  So for client 673,
it would be 6/1/2008 (the very last instance release date for 673)
subtract 9/6/2007 (the very first instance of the entrance date for that
673).

Second, I need to do the same but by agency id and then client id.  Again
using client 673, and agency id "BY" it would be 2/12/2008 subtract
9/6/2007.

I would so appreciate some help on the syntax.

Thanks Tamra

=====================
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: Calculate date difference based on conditions -nested IDs

Mahbub Khandoker
Hi there,
Hopefully this will serve your purpose.

DATA LIST free /ClientID(a3)  AgencyID(a3) EntranceDate(ADATE) ReleaseDate(ADATE).
BEGIN DATA
559 AL 9/6/2007 9/14/2007
604 AW 9/7/2007 1/18/2008
604 BU 1/28/2008 6/1/2008
673 BY 9/6/2007 12/18/2008
673 BY 1/28/2008 2/12/2008
673 EK 2/13/2008 6/1/2008
END DATA.

*To get date difference by ID.
AGGREGATE
  /OUTFILE=* MODE=ADDVARIABLES
  /BREAK=ClientID
  /EntranceDate_first=FIRST(EntranceDate)
  /ReleaseDate_last=LAST(ReleaseDate).

Compute Date_Diff_ByID=Ctime.days(ReleaseDate_last-EntranceDate_first).
Execute.

*To get date difference by ID by AgencyID.
AGGREGATE
  /OUTFILE=* MODE=ADDVARIABLES
  /BREAK=ClientID AgencyID
  /EntranceDate_firstAg=FIRST(EntranceDate)
  /ReleaseDate_lastAg=LAST(ReleaseDate).

Compute Date_Diff_ByIDAgency=Ctime.days(ReleaseDate_lastAg-EntranceDate_firstAg).
Execute.

Cheers!
Mahbub

Mahbub Khandoker
Decision Support
Tel: 416 535 8501 Ex 6534

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Tamra Boyce
Sent: Friday, May 16, 2008 1:38 PM
To: [hidden email]
Subject: Calculate date difference based on conditions -nested IDs

I have a file with 5,000 or so cases.  All cases have two id’s, a unique
client id and an agency id.  Each client may have multiple agency visits
with multiple entrance and release dates.  For example, the dataset can
look like this:

ClientID       AgencyID       EntranceDate ReleaseDate
559       AL  9/6/2007 9/14/2007
604       AW  9/7/2007 1/18/2008
604      BU  1/28/2008 6/1/2008
673       BY  9/6/2007 12/18/2008
673       BY  1/28/2008 2/12/2008
673      EK  2/13/2008 6/1/2008

First, I need to calculate the date difference between the very last
release date and the very first entrance date by ID.  So for client 673,
it would be 6/1/2008 (the very last instance release date for 673)
subtract 9/6/2007 (the very first instance of the entrance date for that
673).

Second, I need to do the same but by agency id and then client id.  Again
using client 673, and agency id "BY" it would be 2/12/2008 subtract
9/6/2007.

I would so appreciate some help on the syntax.

Thanks Tamra

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

______________________________________________________________________
This email has been scanned by the CAMH Email Security System.
______________________________________________________________________


______________________________________________________________________
This email has been scanned by the CAMH Email Security System.
______________________________________________________________________

=====================
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: Calculate date difference based on conditions -nested IDs

Tamra Boyce
In reply to this post by Tamra Boyce
That worked perfectly!  Thanks so much.


On Fri, 16 May 2008 14:48:22 -0400, Mahbub Khandoker
<[hidden email]> wrote:

>Hi there,
>Hopefully this will serve your purpose.
>
>DATA LIST free /ClientID(a3)  AgencyID(a3) EntranceDate(ADATE) ReleaseDate
(ADATE).

>BEGIN DATA
>559 AL 9/6/2007 9/14/2007
>604 AW 9/7/2007 1/18/2008
>604 BU 1/28/2008 6/1/2008
>673 BY 9/6/2007 12/18/2008
>673 BY 1/28/2008 2/12/2008
>673 EK 2/13/2008 6/1/2008
>END DATA.
>
>*To get date difference by ID.
>AGGREGATE
>  /OUTFILE=* MODE=ADDVARIABLES
>  /BREAK=ClientID
>  /EntranceDate_first=FIRST(EntranceDate)
>  /ReleaseDate_last=LAST(ReleaseDate).
>
>Compute Date_Diff_ByID=Ctime.days(ReleaseDate_last-EntranceDate_first).
>Execute.
>
>*To get date difference by ID by AgencyID.
>AGGREGATE
>  /OUTFILE=* MODE=ADDVARIABLES
>  /BREAK=ClientID AgencyID
>  /EntranceDate_firstAg=FIRST(EntranceDate)
>  /ReleaseDate_lastAg=LAST(ReleaseDate).
>
>Compute Date_Diff_ByIDAgency=Ctime.days(ReleaseDate_lastAg-
EntranceDate_firstAg).

>Execute.
>
>Cheers!
>Mahbub
>
>Mahbub Khandoker
>Decision Support
>Tel: 416 535 8501 Ex 6534
>
>-----Original Message-----
>From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Tamra Boyce

>Sent: Friday, May 16, 2008 1:38 PM
>To: [hidden email]
>Subject: Calculate date difference based on conditions -nested IDs
>
>I have a file with 5,000 or so cases.  All cases have two id’s, a unique
>client id and an agency id.  Each client may have multiple agency visits
>with multiple entrance and release dates.  For example, the dataset can
>look like this:
>
>ClientID       AgencyID       EntranceDate ReleaseDate
>559       AL  9/6/2007 9/14/2007
>604       AW  9/7/2007 1/18/2008
>604      BU  1/28/2008 6/1/2008
>673       BY  9/6/2007 12/18/2008
>673       BY  1/28/2008 2/12/2008
>673      EK  2/13/2008 6/1/2008
>
>First, I need to calculate the date difference between the very last
>release date and the very first entrance date by ID.  So for client 673,
>it would be 6/1/2008 (the very last instance release date for 673)
>subtract 9/6/2007 (the very first instance of the entrance date for that
>673).
>
>Second, I need to do the same but by agency id and then client id.  Again
>using client 673, and agency id "BY" it would be 2/12/2008 subtract
>9/6/2007.
>
>I would so appreciate some help on the syntax.
>
>Thanks Tamra
>
>=====================
>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
>
>______________________________________________________________________
>This email has been scanned by the CAMH Email Security System.
>______________________________________________________________________
>
>
>______________________________________________________________________
>This email has been scanned by the CAMH Email Security System.
>______________________________________________________________________
>
>=====================
>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