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
*QUESTION: I need to restructure a file from one line per case to many line per case. 
* I would like the former variable name to become the value labels of the new file.

ANSWER by * rlevesque@videotron.ca.
* Note that the variable name casen is used instead of case. It is not a good idea
to use variable names which corresponds to reserved words. Same 
comment applies to value (I used value1).

* ###### NOTE######  the technique used in this syntax (the syntax literally writes a portion of the syntax) is 
* very powerful and is used in all kinds of solutions.

DATA LIST LIST /ant_s ant_r infer_s infer_r casen.
BEGIN DATA
0 0 1 0 1
1 1 0 0 2
1 0 2 2 3
END DATA.
VARIABLE LABEL 
	ant_s 'anterior_stress' 
	ant_r 'anterior_rest' 
	infer_s 'inferior_stress' 
	infer_r 'inferior_rest'.
LIST.

SAVE OUTFILE='c:\\temp\\data.sav'.
MATCH FILES FILE=* /DROP=casen.
FLIP.
STRING labelstr(A10).
COMPUTE labelstr=CONCAT("'",case_lbl,"'").
COMPUTE segment=$casenum.
FORMATS segment (F8.0).
WRITE OUTFILE 'c:\\temp\\temp.sps' /"ADD VALUE LABELS segment "segment " " labelstr ".".
EXE.

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

* this is your code segment.
VECTOR yvec = ant_s TO infer_r.
LOOP segment = 1 to 4.
COMPUTE value1=yvec(segment).
XSAVE OUTFILE="c:\\temp\\mahr_vec.sav" / KEEP segment casen value1.
END LOOP.
EXECUTE.
GET FILE="c:\\temp\\mahr_vec.sav".
*end of your code.

*Next line does the trick.
INCLUDE 'c:\\temp\\temp.sps'.