Need to select cases that fall within one year of the first case per person.

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

Need to select cases that fall within one year of the first case per person.

jhwagner


Thanks in advance for any assistance anyone can give me on this. I am using SPSS version 23.

I have a dataset of prescription drug dates (and other data not show here for brevity's sake). I wish to select a subset of the data with prescription dates no later than one year after the first prescription for each person in the study. I calculated the variable "oneyear" by simply adding one year the first date for each person.  What I wish to end up with is a flag variable "keep" that indicates if the case is within one year of the first case for each person.


id        date                   drugorder     oneyear          keep
01      18-Jun-2010            1        18-Jun-2011         1
01      27-Dec-2010            2                                   1
01       3-May-2011            3                                   1
01      20-Aug-2011           4
02       9-Oct-2012            1        9-Oct-2013           1              
02      30-Dec-2012            2                                  1
02       3-Jun-2013            3                                   1
02      13-Nov-2013            4
03      18-Apr-2009            1        18-Apr-2010         1
03      10-Dec-2009            2                                  1

I thought that I could use something like match files with /first or perhaps aggregate with first but neither of my attempts have been successful.

This is what I tried using match files:

MATCH FILES  FILE=*
 /BY ID /FIRST=drugorder.
IF date < oneyear keep = 1.

I also thought about taking the calculated value in the "oneyear" variable and filling the value down the column (Lag) and just calculating the difference (datediff) between "oneyear" and "date" but I know there must be a more efficient way.
Reply | Threaded
Open this post in threaded view
|

Re: Need to select cases that fall within one year of the first case per person.

David Marso
Administrator
DATA LIST LIST / ID (N2) Date (EDATE) order (F1).
BEGIN DATA
01      18-Jun-2010            1        
01      27-Dec-2010            2                          
01       3-May-2011            3                                  
01      20-Aug-2011            4
02       9-Oct-2012            1                  
02      30-Dec-2012            2                                
02       3-Jun-2013            3                                  
02      13-Nov-2013            4
03      18-Apr-2009            1        
03      10-Dec-2009            2      
END DATA.
AGGREGATE OUTFILE * MODE ADDVARIABLES / BREAK ID / First_Date=FIRST(date).
COMPUTE keep=DATEDIFF(date,First_date,"years") LE 0.
LIST.
                         
ID       Date order First_Date     keep
 
 1 18.06.2010   1   18.06.2010     1.00
 1 27.12.2010   2   18.06.2010     1.00
 1 03.05.2011   3   18.06.2010     1.00
 1 20.08.2011   4   18.06.2010      .00
 2 09.10.2012   1   09.10.2012     1.00
 2 30.12.2012   2   09.10.2012     1.00
 2 03.06.2013   3   09.10.2012     1.00
 2 13.11.2013   4   09.10.2012      .00
 3 18.04.2009   1   18.04.2009     1.00
 3 10.12.2009   2   18.04.2009     1.00
 
 
Number of cases read:  10    Number of cases listed:  10
jhwagner wrote
Thanks in advance for any assistance anyone can give me on this. I am using SPSS version 23.

I have a dataset of prescription drug dates (and other data not show here for brevity's sake). I wish to select a subset of the data with prescription dates no later than one year after the first prescription for each person in the study. I calculated the variable "oneyear" by simply adding one year the first date for each person.  What I wish to end up with is a flag variable "keep" that indicates if the case is within one year of the first case for each person.


id        date                   drugorder     oneyear          keep
01      18-Jun-2010            1        18-Jun-2011         1
01      27-Dec-2010            2                                   1
01       3-May-2011            3                                   1
01      20-Aug-2011           4
02       9-Oct-2012            1        9-Oct-2013           1              
02      30-Dec-2012            2                                  1
02       3-Jun-2013            3                                   1
02      13-Nov-2013            4
03      18-Apr-2009            1        18-Apr-2010         1
03      10-Dec-2009            2                                  1

I thought that I could use something like match files with /first or perhaps aggregate with first but neither of my attempts have been successful.

This is what I tried using match files:

MATCH FILES  FILE=*
 /BY ID /FIRST=drugorder.
IF date < oneyear keep = 1.

I also thought about taking the calculated value in the "oneyear" variable and filling the value down the column (Lag) and just calculating the difference (datediff) between "oneyear" and "date" but I know there must be a more efficient way.
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: Need to select cases that fall within one year of the first case per person.

Maguin, Eugene
Just curious. What are the second through fifth "*"s doing?
Gene Maguin

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of David Marso
Sent: Friday, September 25, 2015 12:18 AM
To: [hidden email]
Subject: Re: Need to select cases that fall within one year of the first case per person.

DATA LIST LIST / ID (N2) Date (EDATE) order (F1).
BEGIN DATA
01      18-Jun-2010            1        
01      27-Dec-2010            2                          
01       3-May-2011            3                                  
01      20-Aug-2011            4
02       9-Oct-2012            1                  
02      30-Dec-2012            2                                
02       3-Jun-2013            3                                  
02      13-Nov-2013            4
03      18-Apr-2009            1        
03      10-Dec-2009            2      
END DATA.
AGGREGATE OUTFILE * *MODE ADDVARIABLES */ BREAK ID / First_Date=*FIRST*(date).
COMPUTE keep=DATEDIFF(date,First_date,"years") LE 0.
LIST.
                         
ID       Date order First_Date     keep
 
 1 18.06.2010   1   18.06.2010     1.00
 1 27.12.2010   2   18.06.2010     1.00
 1 03.05.2011   3   18.06.2010     1.00
 1 20.08.2011   4   18.06.2010      .00
 2 09.10.2012   1   09.10.2012     1.00
 2 30.12.2012   2   09.10.2012     1.00
 2 03.06.2013   3   09.10.2012     1.00
 2 13.11.2013   4   09.10.2012      .00
 3 18.04.2009   1   18.04.2009     1.00
 3 10.12.2009   2   18.04.2009     1.00
 
 
Number of cases read:  10    Number of cases listed:  10

jhwagner wrote

> Thanks in advance for any assistance anyone can give me on this. I am
> using SPSS version 23.
>
> I have a dataset of prescription drug dates (and other data not show
> here for brevity's sake). I wish to select a subset of the data with
> prescription dates no later than one year after the first prescription
> for each person in the study. I calculated the variable "oneyear" by
> simply adding one year the first date for each person.  What I wish to
> end up with is a flag variable "keep" that indicates if the case is
> within one year of the first case for each person.
>
>
> id        date                   drugorder     oneyear          keep
> 01      18-Jun-2010            1        18-Jun-2011         1
> 01      27-Dec-2010            2                                   1
> 01       3-May-2011            3                                   1
> 01      20-Aug-2011           4
> 02       9-Oct-2012            1        9-Oct-2013           1              
> 02      30-Dec-2012            2                                  1
> 02       3-Jun-2013            3                                   1
> 02      13-Nov-2013            4
> 03      18-Apr-2009            1        18-Apr-2010         1
> 03      10-Dec-2009            2                                  1
>
> I thought that I could use something like match files with /first or
> perhaps aggregate with first but neither of my attempts have been
> successful.
>
> This is what I tried using match files:
>
> MATCH FILES  FILE=*
>  /BY ID /FIRST=drugorder.
> IF date < oneyear keep = 1.
>
> I also thought about taking the calculated value in the "oneyear"
> variable and filling the value down the column (Lag) and just
> calculating the difference (datediff) between "oneyear" and "date" but
> I know there must be a more efficient way.





-----
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?"
--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Need-to-select-cases-that-fall-within-one-year-of-the-first-case-per-person-tp5730663p5730664.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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: Need to select cases that fall within one year of the first case per person.

David Marso
Administrator
They make the code BOLD when viewed on Nabble.
I should probably stop doing that?
---
AGGREGATE OUTFILE * MODE ADDVARIABLES / BREAK ID / First_Date=FIRST(date).
COMPUTE keep=DATEDIFF(date,First_date,"years") LE 0.





Maguin, Eugene wrote
Just curious. What are the second through fifth "*"s doing?
Gene Maguin

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of David Marso
Sent: Friday, September 25, 2015 12:18 AM
To: [hidden email]
Subject: Re: Need to select cases that fall within one year of the first case per person.

DATA LIST LIST / ID (N2) Date (EDATE) order (F1).
BEGIN DATA
01      18-Jun-2010            1        
01      27-Dec-2010            2                          
01       3-May-2011            3                                  
01      20-Aug-2011            4
02       9-Oct-2012            1                  
02      30-Dec-2012            2                                
02       3-Jun-2013            3                                  
02      13-Nov-2013            4
03      18-Apr-2009            1        
03      10-Dec-2009            2      
END DATA.
AGGREGATE OUTFILE * *MODE ADDVARIABLES */ BREAK ID / First_Date=*FIRST*(date).
COMPUTE keep=DATEDIFF(date,First_date,"years") LE 0.
LIST.
                         
ID       Date order First_Date     keep
 
 1 18.06.2010   1   18.06.2010     1.00
 1 27.12.2010   2   18.06.2010     1.00
 1 03.05.2011   3   18.06.2010     1.00
 1 20.08.2011   4   18.06.2010      .00
 2 09.10.2012   1   09.10.2012     1.00
 2 30.12.2012   2   09.10.2012     1.00
 2 03.06.2013   3   09.10.2012     1.00
 2 13.11.2013   4   09.10.2012      .00
 3 18.04.2009   1   18.04.2009     1.00
 3 10.12.2009   2   18.04.2009     1.00
 
 
Number of cases read:  10    Number of cases listed:  10

jhwagner wrote
> Thanks in advance for any assistance anyone can give me on this. I am
> using SPSS version 23.
>
> I have a dataset of prescription drug dates (and other data not show
> here for brevity's sake). I wish to select a subset of the data with
> prescription dates no later than one year after the first prescription
> for each person in the study. I calculated the variable "oneyear" by
> simply adding one year the first date for each person.  What I wish to
> end up with is a flag variable "keep" that indicates if the case is
> within one year of the first case for each person.
>
>
> id        date                   drugorder     oneyear          keep
> 01      18-Jun-2010            1        18-Jun-2011         1
> 01      27-Dec-2010            2                                   1
> 01       3-May-2011            3                                   1
> 01      20-Aug-2011           4
> 02       9-Oct-2012            1        9-Oct-2013           1              
> 02      30-Dec-2012            2                                  1
> 02       3-Jun-2013            3                                   1
> 02      13-Nov-2013            4
> 03      18-Apr-2009            1        18-Apr-2010         1
> 03      10-Dec-2009            2                                  1
>
> I thought that I could use something like match files with /first or
> perhaps aggregate with first but neither of my attempts have been
> successful.
>
> This is what I tried using match files:
>
> MATCH FILES  FILE=*
>  /BY ID /FIRST=drugorder.
> IF date < oneyear keep = 1.
>
> I also thought about taking the calculated value in the "oneyear"
> variable and filling the value down the column (Lag) and just
> calculating the difference (datediff) between "oneyear" and "date" but
> I know there must be a more efficient way.





-----
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?"
--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Need-to-select-cases-that-fall-within-one-year-of-the-first-case-per-person-tp5730663p5730664.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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
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: Need to select cases that fall within one year of the first case per person.

Bruce Weaver
Administrator
Ah, good catch, David.  I was viewing in Nabble, so did not immediately understand what extra stars Gene was talking about.  ;-)


David Marso wrote
They make the code BOLD when viewed on Nabble.
I should probably stop doing that?
---
AGGREGATE OUTFILE * MODE ADDVARIABLES / BREAK ID / First_Date=FIRST(date).
COMPUTE keep=DATEDIFF(date,First_date,"years") LE 0.





Maguin, Eugene wrote
Just curious. What are the second through fifth "*"s doing?
Gene Maguin

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of David Marso
Sent: Friday, September 25, 2015 12:18 AM
To: [hidden email]
Subject: Re: Need to select cases that fall within one year of the first case per person.

DATA LIST LIST / ID (N2) Date (EDATE) order (F1).
BEGIN DATA
01      18-Jun-2010            1        
01      27-Dec-2010            2                          
01       3-May-2011            3                                  
01      20-Aug-2011            4
02       9-Oct-2012            1                  
02      30-Dec-2012            2                                
02       3-Jun-2013            3                                  
02      13-Nov-2013            4
03      18-Apr-2009            1        
03      10-Dec-2009            2      
END DATA.
AGGREGATE OUTFILE * *MODE ADDVARIABLES */ BREAK ID / First_Date=*FIRST*(date).
COMPUTE keep=DATEDIFF(date,First_date,"years") LE 0.
LIST.
                         
ID       Date order First_Date     keep
 
 1 18.06.2010   1   18.06.2010     1.00
 1 27.12.2010   2   18.06.2010     1.00
 1 03.05.2011   3   18.06.2010     1.00
 1 20.08.2011   4   18.06.2010      .00
 2 09.10.2012   1   09.10.2012     1.00
 2 30.12.2012   2   09.10.2012     1.00
 2 03.06.2013   3   09.10.2012     1.00
 2 13.11.2013   4   09.10.2012      .00
 3 18.04.2009   1   18.04.2009     1.00
 3 10.12.2009   2   18.04.2009     1.00
 
 
Number of cases read:  10    Number of cases listed:  10

jhwagner wrote
> Thanks in advance for any assistance anyone can give me on this. I am
> using SPSS version 23.
>
> I have a dataset of prescription drug dates (and other data not show
> here for brevity's sake). I wish to select a subset of the data with
> prescription dates no later than one year after the first prescription
> for each person in the study. I calculated the variable "oneyear" by
> simply adding one year the first date for each person.  What I wish to
> end up with is a flag variable "keep" that indicates if the case is
> within one year of the first case for each person.
>
>
> id        date                   drugorder     oneyear          keep
> 01      18-Jun-2010            1        18-Jun-2011         1
> 01      27-Dec-2010            2                                   1
> 01       3-May-2011            3                                   1
> 01      20-Aug-2011           4
> 02       9-Oct-2012            1        9-Oct-2013           1              
> 02      30-Dec-2012            2                                  1
> 02       3-Jun-2013            3                                   1
> 02      13-Nov-2013            4
> 03      18-Apr-2009            1        18-Apr-2010         1
> 03      10-Dec-2009            2                                  1
>
> I thought that I could use something like match files with /first or
> perhaps aggregate with first but neither of my attempts have been
> successful.
>
> This is what I tried using match files:
>
> MATCH FILES  FILE=*
>  /BY ID /FIRST=drugorder.
> IF date < oneyear keep = 1.
>
> I also thought about taking the calculated value in the "oneyear"
> variable and filling the value down the column (Lag) and just
> calculating the difference (datediff) between "oneyear" and "date" but
> I know there must be a more efficient way.





-----
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?"
--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Need-to-select-cases-that-fall-within-one-year-of-the-first-case-per-person-tp5730663p5730664.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: Need to select cases that fall within one year of the first case per person.

jhwagner
In reply to this post by David Marso
Thank you very much David.  This worked perfectly for me.