1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
* I need to restructure a data file so that each line will become many lines.
* Raynald Levesque www.spsstools.net .

* Create some data fore illustration purposes.

DATA LIST LIST /id sit1 sit2 sit3 sit4 age.
BEGIN DATA
1  3    4    5     .     29
2   .    3    5    2     31
3  1    3    .     5     18
END DATA.
SAVE OUTFILE='c:\\temp\\mydata.sav'.

* Method 1.
* This works with any versions of SPSS.

VECTOR myvector = sit1 TO sit4.
LOOP sit=1 TO 4.
- COMPUTE evaluate=myvector(sit) .
- DO IF NOT SYSMIS(evaluate).
- XSAVE OUTFILE='c:\\temp\\tall data.sav' /KEEP=id age sit evaluate. 
- END IF .
END LOOP.
EXECUTE.

GET FILE='c:\\temp\\tall data.sav'.
LIST.

* Method 2.
* this requires version 11 or higher.

GET FILE='c:\\temp\\mydata.sav'.
VARSTOCASES  /MAKE evaluate FROM sit1 sit2 sit3 sit4
 /INDEX = sit "sit"(4)
 /KEEP =  id age
 /NULL = DROP.
LIST.


** Both methods generate the following output:

      id      age  sit evaluate

    1.00    29.00    1     3.00
    1.00    29.00    2     4.00
    1.00    29.00    3     5.00
    2.00    31.00    2     3.00
    2.00    31.00    3     5.00
    2.00    31.00    4     2.00
    3.00    18.00    1     1.00
    3.00    18.00    2     3.00
    3.00    18.00    4     5.00


Number of cases read:  9    Number of cases listed:  9