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
* To apply the string values of lab1as value labels to variable var1.
* rlevesque@videotron.ca.

* define some sample data.
DATA LIST LIST /var1(F8) lab1(A8).
BEGIN DATA.
1 one 
1 one 
2 two 
3 three 
3 three
END DATA.
LIST.

SAVE OUTFILE='test1.sav'.

* need first to keep only cases with unique value labels.
AGGREGATE
  /OUTFILE=*
  /BREAK=var1
  /lab1 = FIRST(lab1) .

STRING quot(A1).
COMPUTE quot="'".
* Note: the dimension of lab2 must be 2 characters larger than the dimention of lab1.
* However the max dimension of lab2 is 60. If dim of lab1 exceeds 58, use
*	COMPUTE lab2=CONCAT(quot,SUBSTR(lab1,1,58),quot) instead of line below.
STRING lab2(A10).
COMPUTE lab2=CONCAT(quot,lab1,quot).

* write a syntax file to assign the labels.
WRITE OUTFILE 'temp.sps' /"ADD VALUE LABELS var1 " var1 " " lab2 ".".
EXE.

* Get original data file then call syntax to define the value labels.
GET  FILE='test1.sav'.
INCLUDE 'temp.sps'.