Hi all,

I have a data set that has what I would call 'diagnosis' and 'person' who

put down the information in multiple encounters (with the same case).

first_in_LOOP.xlsx

<

http://spssx-discussion.1045642.n5.nabble.com/file/t340420/first_in_LOOP.xlsx>

The data is generated as a "case" have multiple encounters with a 'person',

each encounter get a code (disp1 to disp9) by the person who is at the

office (idTime1 to idTime9).

What I would like to extract the person ID when the FIRST diagnosis "12.215"

has been given. So, the case 4 has the code "12.215" in the second encounter

and the person ID is "46".The diagnosis "12.215" can be given at any time

and multiple time (see cases 8 and 10).

I thought that using a LOOP will solve this. So, I wrote 3 LOOP to extract

the information, BUT there must be an "easier" way like "stopping" the LOOP

in the FIRST "12.215" and storing the ID associated with. I could not find

the information if this is possible.

So, the code that I used is similar to this:

compute BO.01=0.

compute BO.02=0.

compute BO.03=0.

compute BO.04=0.

compute BO.05=0.

compute BO.06=0.

compute BO.07=0.

compute BO.08=0.

compute BO.09=0.

*This is to locate where the 12.215 happens.

vector sign_BO.=disp1 to disp9.

vector mark_BO.=BO.01 to BO.09.

loop #i=1 to 9.

if any (sign_BO.(#i), 12.215) mark_BO.(#i)=1.

end loop.

exe.

*This will drag the values across the 2nd loop.

compute sBO.01=BO.01.

compute sBO.02=0.

compute sBO.03=0.

compute sBO.04=0.

compute sBO.05=0.

compute sBO.06=0.

compute sBO.07=0.

compute sBO.08=0.

compute sBO.09=0.

vector sign_BO.=BO.01 to BO.09.

vector sum_BO.=sBO.01 to sBO.09.

loop #i=2 to 9.

if sign_BO.(#i)=0 sum_BO.(#i)=sum_BO.(#i-1).

if sign_BO.(#i)=1 sum_BO.(#i)=sum_BO.(#i-1)+1.

end loop.

exe.

*first disp .

compute firstID=$sysmis.

if BO.01=1 firstID=idTime1.

*if happens later.

*This will take where the first change occurs, and 'mark' them as the first.

vector sum2_BO.=sBO.01 to sBO.09.

vector first_BO.=idTime1 to idTime9.

loop #i=2 to 9.

if sum2_BO.(#i)=1 and sum2_BO.(#i-1)=0 firstID=first_BO.(#i).

end loop.

execute.

I could also have reversed the timing.order of the variables by reordering

the dataset and use one loop to find the "last", but the actual dataset is

bigger and complicated than what I am attaching.

Thank you in advance for your time.

Ki

--

Sent from:

http://spssx-discussion.1045642.n5.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