How do I merge the content of SPSS variables from different columns

Viewed 44

I want to create five new variable K1 K2 K3 K4 K5 where the table below will return the content for each in their order of entry as shown on Fig 2

SN  ID1 ID2 ID3 ID4 ID5 IE1 IE2 IE3 IE4 IE5
1   a   b   c           d   e           
2   b   a       f       c   k   

Fig 2

SN  K1 K2 K3 K4 K5
1   a  b  c  d  e
2   b  a  f  c  k
1 Answers

Here's a possible way to do it:

(first recreating your example data to demonstrate on:)

data list list/ SN (f1)  ID1 to ID5 IE1 to IE5 (10a1).
begin data
 1,   "a",   "b",   "c", , ,  "d",   "e", , ,     
 2,   "b",   "a", ,  "f", ,   "c",   "k", , , 
end data.

This is your example data, now you can run the following syntax, which will yield the results you expected:

string K1 to K5 (a1).
vector K=K1 to K5.
compute #x=1.
do repeat id=ID1 to IE5.
    do if id<>"".
        compute K(#x)=id. /* correction made here .
        compute #x=#x+1.
    end if.
end repeat.
Related