# Looking for appropriate loop

#### nawick

##### New Member
Hi! Hello!
I am looking for solution which lead me from yellow to green results like that:

As you can see, there are 0-1 coding data with sysmis, always five 1 per line. Thre are 20 variables (p1,p2, ..., p20) and I need to recode them into 5, using number of columns. I have started with recodig 1-values ...

... and I can replace sysmis but I found it difficult to build some loops to make next step. It is necessary to create SPSS script to do that.
Do you have any idea to make it in easy way?

Thanks!

Last edited:

#### EdGr

##### Member
How about something like

Do repeat KX = k1 to k5.
Compute KX = 0.
end repeat.

Do repeat px = P1 to p20.
ST = 0.
Do if px > 0.
do repeat ky = k1 to k5.
do if ky = 0 and ST = 0.
ky = px.
ST = 1.
end if.
end repeat.
end if.
End repeat.

I haven't tested this. The "ST" is just to make it stop changing K to a value once the first one has been changed for a given p.

You could skip converting the 1's to numbers if you had another variable Do repeat N = 1 to 20. Then set ky equal to that when px is > 0.

Let me know if this works!

Ed

Ed

#### EdGr

##### Member
Hm, this shows nice indenting when I edit it, but removes all the indents when I view it. Hope you can see the indents -- much easier to figure out.