Identifying the last instance of an event

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

Identifying the last instance of an event

Tamra Boyce
Dear All,

I have a dataset of 500 clients who have had anywhere from 1 to 50 service
events.  I want to grab the last event for each client and put it into a
new variable "Last Event".  For some it may be their first service event,
for others it may be the 10th, 24th or 50th.

Any help would be appreciated it.

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: Identifying the last instance of an event

Bruce Weaver
Administrator
Tamra Boyce wrote
Dear All,

I have a dataset of 500 clients who have had anywhere from 1 to 50 service
events.  I want to grab the last event for each client and put it into a
new variable "Last Event".  For some it may be their first service event,
for others it may be the 10th, 24th or 50th.

Any help would be appreciated it.

Thanks.

Tamra
How is your data file structured?  I.e., is there one row per client with events in multiple columns?  Or do you have multiple rows per client with a single EVENT variable (and some index variable for time or visit)?  If it is the latter situation, sort by time (or visit), and use the LAST subcommand of MATCH (or ADD) FILES.  E.g.,

sort cases by ID visit .
match files
 file = * /
 by ID /
 last = LastVisit .
if LastVisit LastEvent = Event .
exe.

This assumes EVENT is numeric.  If it is a string variable, you'd have to declare a new string variable called LastEvent first.  E.g.,

string LastEvent (a50).

--
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: Identifying the last instance of an event

Tamra Boyce

Yes, there is one row per client with events in multiple columns. The events are services with a numerical code.   For example

Client ID      Event1        Event2               Event3 ............Event50
238              34                        78                90                          46
498               23                90                   01                      34


Thanks again.




Bruce Weaver <[hidden email]>
Sent by: "SPSSX(r) Discussion" <[hidden email]>

09/30/2009 04:58 PM

Please respond to
Bruce Weaver <[hidden email]>

To
[hidden email]
cc
Subject
Re: Identifying the last instance of an event





Tamra Boyce wrote:
>
> Dear All,
>
> I have a dataset of 500 clients who have had anywhere from 1 to 50 service
> events.  I want to grab the last event for each client and put it into a
> new variable "Last Event".  For some it may be their first service event,
> for others it may be the 10th, 24th or 50th.
>
> Any help would be appreciated it.
>
> Thanks.
>
> Tamra
>

How is your data file structured?  I.e., is there one row per client with
events in multiple columns?  Or do you have multiple rows per client with a
single EVENT variable (and some index variable for time or visit)?  If it is
the latter situation, sort by time (or visit), and use the LAST subcommand
of MATCH (or ADD) FILES.  E.g.,

sort cases by ID visit .
match files
file = * /
by ID /
last = LastVisit .
if LastVisit LastEvent = Event .
exe.

This assumes EVENT is numeric.  If it is a string variable, you'd have to
declare a new string variable called LastEvent first.  E.g.,

string LastEvent (a50).



-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/
"When all else fails, RTFM."

NOTE:  My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.
--
View this message in context: http://www.nabble.com/Identifying-the-last-instance-of-an-event-tp25689384p25689721.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





Disclaimer: Information in this message or an attachment may be government data and thereby subject to the Minnesota Government Data Practices Act, Minnesota Statutes, Chapter 13, may be subject to attorney-client or work product privilege, may be confidential, privileged, proprietary, or otherwise protected, and the unauthorized review, copying, retransmission, or other use or disclosure of the information is strictly prohibited. If you are not the intended recipient of this message, please immediately notify the sender of the transmission error and then promptly delete this message from your computer system.
Reply | Threaded
Open this post in threaded view
|

Re: Identifying the last instance of an event

John McConnell-2

Hi Tamra

 

You could shortcut this using a script or a macro but how about (untested)…

 

If event1 > 0 Lastevent=event1.

If event2 > 0 Lastevent=event2.

If event3 > 0 Lastevent=event3.

… and so on

 

Hth

 

John

 

From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Tamra Boyce
Sent: 01 October 2009 12:59
To: [hidden email]
Subject: Re: Identifying the last instance of an event

 


Yes, there is one row per client with events in multiple columns. The events are services with a numerical code.   For example

Client ID      Event1        Event2               Event3 ............Event50
238              34                        78                90                          46
498               23                90                   01                      34


Thanks again.



Bruce Weaver <[hidden email]>
Sent by: "SPSSX(r) Discussion" <[hidden email]>

09/30/2009 04:58 PM

Please respond to
Bruce Weaver <[hidden email]>

To

[hidden email]

cc

Subject

Re: Identifying the last instance of an event

 




Tamra Boyce wrote:
>
> Dear All,
>
> I have a dataset of 500 clients who have had anywhere from 1 to 50 service
> events.  I want to grab the last event for each client and put it into a
> new variable "Last Event".  For some it may be their first service event,
> for others it may be the 10th, 24th or 50th.
>
> Any help would be appreciated it.
>
> Thanks.
>
> Tamra
>

How is your data file structured?  I.e., is there one row per client with
events in multiple columns?  Or do you have multiple rows per client with a
single EVENT variable (and some index variable for time or visit)?  If it is
the latter situation, sort by time (or visit), and use the LAST subcommand
of MATCH (or ADD) FILES.  E.g.,

sort cases by ID visit .
match files
file = * /
by ID /
last = LastVisit .
if LastVisit LastEvent = Event .
exe.

This assumes EVENT is numeric.  If it is a string variable, you'd have to
declare a new string variable called LastEvent first.  E.g.,

string LastEvent (a50).



-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/
"When all else fails, RTFM."

NOTE:  My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.
--
View this message in context: http://www.nabble.com/Identifying-the-last-instance-of-an-event-tp25689384p25689721.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





Disclaimer: Information in this message or an attachment may be government data and thereby subject to the Minnesota Government Data Practices Act, Minnesota Statutes, Chapter 13, may be subject to attorney-client or work product privilege, may be confidential, privileged, proprietary, or otherwise protected, and the unauthorized review, copying, retransmission, or other use or disclosure of the information is strictly prohibited. If you are not the intended recipient of this message, please immediately notify the sender of the transmission error and then promptly delete this message from your computer system.

Reply | Threaded
Open this post in threaded view
|

Re: Identifying the last instance of an event

John F Hall
In reply to this post by Tamra Boyce
Long time since I did anything quite like this, but if every event is recorded for each client (and perhaps even if not) you could try something like:
 
count events = event1 to event50 (1 thru 50).
do repeat
    x=1 to 50
    /y=event1 to event50
if events = x latest = y.
end repeat.
 
but check the exact syntax in the manual first
 
 
----- Original Message -----
Sent: Thursday, October 01, 2009 1:59 PM
Subject: Re: Identifying the last instance of an event


Yes, there is one row per client with events in multiple columns. The events are services with a numerical code.   For example

Client ID      Event1        Event2               Event3 ............Event50
238              34                        78                90                          46
498               23                90                   01                      34


Thanks again.




Bruce Weaver <[hidden email]>
Sent by: "SPSSX(r) Discussion" <[hidden email]>

09/30/2009 04:58 PM

Please respond to
Bruce Weaver <[hidden email]>

To
[hidden email]
cc
Subject
Re: Identifying the last instance of an event





Tamra Boyce wrote:

>
> Dear All,
>
> I have a dataset of 500 clients who have had anywhere from 1 to 50 service
> events.  I want to grab the last event for each client and put it into a
> new variable "Last Event".  For some it may be their first service event,
> for others it may be the 10th, 24th or 50th.
>
> Any help would be appreciated it.
>
> Thanks.
>
> Tamra
>

How is your data file structured?  I.e., is there one row per client with
events in multiple columns?  Or do you have multiple rows per client with a
single EVENT variable (and some index variable for time or visit)?  If it is
the latter situation, sort by time (or visit), and use the LAST subcommand
of MATCH (or ADD) FILES.  E.g.,

sort cases by ID visit .
match files
file = * /
by ID /
last = LastVisit .
if LastVisit LastEvent = Event .
exe.

This assumes EVENT is numeric.  If it is a string variable, you'd have to
declare a new string variable called LastEvent first.  E.g.,

string LastEvent (a50).



-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/
"When all else fails, RTFM."

NOTE:  My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.
--
View this message in context: http://www.nabble.com/Identifying-the-last-instance-of-an-event-tp25689384p25689721.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





Disclaimer: Information in this message or an attachment may be government data and thereby subject to the Minnesota Government Data Practices Act, Minnesota Statutes, Chapter 13, may be subject to attorney-client or work product privilege, may be confidential, privileged, proprietary, or otherwise protected, and the unauthorized review, copying, retransmission, or other use or disclosure of the information is strictly prohibited. If you are not the intended recipient of this message, please immediately notify the sender of the transmission error and then promptly delete this message from your computer system.
Reply | Threaded
Open this post in threaded view
|

Re: Identifying the last instance of an event

Bruce Weaver
Administrator
In reply to this post by Tamra Boyce
Tamra Boyce wrote
Yes, there is one row per client with events in multiple columns. The
events are services with a numerical code.   For example

Client ID      Event1   Event2         Event3 ............Event50
238           34                        78              90        46
498            23               90                   01   34


Thanks again.
I can't tell whether the EVENT variables are numeric or string.  It's not completely clear what happens when someone has less than 50 events either, but I assume that they have either a SYSMIS, user-defined missing value, or blank string from that point up to EVENT50.  If this is correct, then something like the following should work.

* If EVENT is numeric, and 999 means MISSING.

data list list / event1 to event5 (5f3) . /* read in some sample data .
begin data
034 078 090 046 023
023 090 001 034 999
078 090 046 999 999
090 001 999 999 999
010 999 999 999 999
999 999 999 999 999
end data.

missing values event1 to event5 (999).

vector e = event1 to event5.
loop #i = 1 to 5 .
- if ~missing(e(#i)) lastevent = e(#i).
end loop.
format all (n3.0).
list.

* If EVENT is a string variable, and '999' means MISSING .

data list list / event1 to event5 (5a3) . /* read in some sample data .
begin data
034 078 090 046 023
023 090 001 034 999
078 090 046 999 999
090 001 999 999 999
010 999 999 999 999
999 999 999 999 999
end data.

string lastevent(a3).
vector e = event1 to event5.
loop #i = 1 to 5 .
- if (e(#i) NE '999') lastevent = e(#i).
end loop.
list.
--
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: Identifying the last instance of an event

Tamra Boyce

This worked.  Sorry you had to make assumptions but your solution worked beautifully.  And thanks to those of you who offered solutions, as well, I spent the day trying to make them work.  

Thanks again.



Tamra  





Bruce Weaver <[hidden email]>
Sent by: "SPSSX(r) Discussion" <[hidden email]>

10/01/2009 02:05 PM

Please respond to
Bruce Weaver <[hidden email]>

To
[hidden email]
cc
Subject
Re: Identifying the last instance of an event





Tamra Boyce wrote:
>
> Yes, there is one row per client with events in multiple columns. The
> events are services with a numerical code.   For example
>
> Client ID      Event1   Event2         Event3 ............Event50
> 238           34                        78              90        46
> 498            23               90                   01   34
>
>
> Thanks again.
>

I can't tell whether the EVENT variables are numeric or string.  It's not
completely clear what happens when someone has less than 50 events either,
but I assume that they have either a SYSMIS, user-defined missing value, or
blank string from that point up to EVENT50.  If this is correct, then
something like the following should work.

* If EVENT is numeric, and 999 means MISSING.

data list list / event1 to event5 (5f3) . /* read in some sample data .
begin data
034 078 090 046 023
023 090 001 034 999
078 090 046 999 999
090 001 999 999 999
010 999 999 999 999
999 999 999 999 999
end data.

missing values event1 to event5 (999).

vector e = event1 to event5.
loop #i = 1 to 5 .
- if ~missing(e(#i)) lastevent = e(#i).
end loop.
format all (n3.0).
list.

* If EVENT is a string variable, and '999' means MISSING .

data list list / event1 to event5 (5a3) . /* read in some sample data .
begin data
034 078 090 046 023
023 090 001 034 999
078 090 046 999 999
090 001 999 999 999
010 999 999 999 999
999 999 999 999 999
end data.

string lastevent(a3).
vector e = event1 to event5.
loop #i = 1 to 5 .
- if (e(#i) NE '999') lastevent = e(#i).
end loop.
list.


-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/
"When all else fails, RTFM."

NOTE:  My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.
--
View this message in context: http://www.nabble.com/Identifying-the-last-instance-of-an-event-tp25689384p25704718.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





Disclaimer: Information in this message or an attachment may be government data and thereby subject to the Minnesota Government Data Practices Act, Minnesota Statutes, Chapter 13, may be subject to attorney-client or work product privilege, may be confidential, privileged, proprietary, or otherwise protected, and the unauthorized review, copying, retransmission, or other use or disclosure of the information is strictly prohibited. If you are not the intended recipient of this message, please immediately notify the sender of the transmission error and then promptly delete this message from your computer system.