Extracting ID the first value in a LOOP

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

Extracting ID the first value in a LOOP

Ki Park
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
Reply | Threaded
Open this post in threaded view
|

Re: Extracting ID the first value in a LOOP

Jon Peck
Define a vector of all 18 variables.
Use LOOP 1 through 9 to find the value.
Find person as index + 9.
BREAK.

Alternatively, create two vectors and index into the second one for the person I’d.

On Thu, Dec 6, 2018 at 11:08 AM Ki Park <[hidden email]> wrote:
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
--
Jon K Peck
[hidden email]

===================== 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: Extracting ID the first value in a LOOP

Ki Park
Thank you Jon.
Your note made me think :o) and lead to this solution that does the same
work as the long version of the previous codes that used.

compute count_id=$sysmis.
vector disp_BO.=disp1 to idTime9.
loop #i=1 to 9.
if disp_BO.(#i)=12.215 count_id= disp_BO.(#i+9) .
end loop if disp_BO.(#i)=12.215.

I did not know that you can add a conditional statement in the END LOOP, and
that made all the difference to break the loop in the first 12.215.

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
Reply | Threaded
Open this post in threaded view
|

Re: Extracting ID the first value in a LOOP

Art Kendall
I strongly urge you to maintain the valuable distinction between system
missing and user missing.

System missing should be reserved for the situation where the system sets
that value because it is unable to do what you ask it to do. It should be a
red flag when you see sysmis assigned by the user.

In this instance the user, you, set the value to be held in count_ID.  You
may or not want to consider that a user missing value in later processing.

compute count_id='none'.
value labels count_id 'none' 'code 12.215 not found in this case'.



-----
Art Kendall
Social Research Consultants
--
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
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: Extracting ID the first value in a LOOP

Ki Park
Yes, you are absolutely right Art. That is what is on my code in the syntax
file.
Thank you.
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