Selecting all cases within a group if any of the cases are equal to a specific value

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

Selecting all cases within a group if any of the cases are equal to a specific value

ariel barak
Fellow Users,

I'd like to know if there is a more elegant syntax solution to what I do
currently to select cases. I'm working with data where individuals are
assigned a patient number and are given admission numbers and are then
assigned to various programs. What I would like to do is to flag all cases
for an individual within an admission where the program is PROB. Currently,
my approach (syntax below) is to flag admissions where the program is PROB
and then to aggregate the data by patientid and admissionid and then sum the
flag variable. I then merge the flag variable back onto the original dataset
and selected those cases where the sum of the flag variable was greater than
0. It seems like there should be a way to do this with less code...is there?

Thanks in advance,
Ari

*Sample Data.
DATA LIST LIST /patientid(F8) admissionid (F8) program (A7).
BEGIN DATA
0041 101843 PROB
0041 101843 INTAKE
0543 103214 CPS
0714 108471 PROB
0843 90471 LTS
END DATA.

DATASET NAME StartData.

COMPUTE PROB=0.
IF program='PROB' PROB=1.
EXE.

DATASET DECLARE Prob.
AGGREGATE
  /OUTFILE='Prob'
  /BREAK=patientid admissionid
  /PROBonAdmissionID=SUM(PROB).

MATCH FILES /FILE=*
  /TABLE='Prob'
  /BY  patientid admissionid.
EXECUTE.

SELECT IF PROBonAdmissionID>0.
EXE.

=====================
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: Selecting all cases within a group if any of the cases are equal to a specific value

Jignesh Sutar
Use the MODE function within AGGREGATE command.

*Sample Data.
DATA LIST LIST /patientid(F8) admissionid (F8) program (A7).
BEGIN DATA
0041 101843 PROB
0041 101843 INTAKE
0543 103214 CPS
0714 108471 PROB
0843 90471 LTS
END DATA.

COMPUTE PROB=0.
IF program='PROB' PROB=1.

AGGREGATE
 /OUTFILE=* MODE=ADDVARIABLES
 /BREAK=patientid admissionid
 /PROBonAdmissionID=SUM(PROB).

SELECT IF PROBonAdmissionID>0.
LIST.

HTH,
Jignesh

2008/10/16 Ariel Barak <[hidden email]>

> Fellow Users,
>
> I'd like to know if there is a more elegant syntax solution to what I do
> currently to select cases. I'm working with data where individuals are
> assigned a patient number and are given admission numbers and are then
> assigned to various programs. What I would like to do is to flag all cases
> for an individual within an admission where the program is PROB. Currently,
> my approach (syntax below) is to flag admissions where the program is PROB
> and then to aggregate the data by patientid and admissionid and then sum
> the
> flag variable. I then merge the flag variable back onto the original
> dataset
> and selected those cases where the sum of the flag variable was greater
> than
> 0. It seems like there should be a way to do this with less code...is
> there?
>
> Thanks in advance,
> Ari
>
> *Sample Data.
> DATA LIST LIST /patientid(F8) admissionid (F8) program (A7).
> BEGIN DATA
> 0041 101843 PROB
> 0041 101843 INTAKE
> 0543 103214 CPS
> 0714 108471 PROB
> 0843 90471 LTS
> END DATA.
>
> DATASET NAME StartData.
>
> COMPUTE PROB=0.
> IF program='PROB' PROB=1.
> EXE.
>
> DATASET DECLARE Prob.
> AGGREGATE
>  /OUTFILE='Prob'
>  /BREAK=patientid admissionid
>  /PROBonAdmissionID=SUM(PROB).
>
> MATCH FILES /FILE=*
>  /TABLE='Prob'
>  /BY  patientid admissionid.
> EXECUTE.
>
> SELECT IF PROBonAdmissionID>0.
> EXE.
>
> =====================
> 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