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
*(Q)I have a data File without any data, but with the description of the
	variables, labels, etc. that I need.
* My data is contained in a different file
  How can I merge the two files in a way, that the defined variables match
	the data entries.The data entries are in exactly the same order as 
	the defined variables but the variable names are different.


*(A) Sent by email to the author of the question by
	Raynald Levesque on 2002/03/08.


DATA LIST LIST /a b c.
BEGIN DATA
1 1 2
2 3 4
END DATA.
SAVE OUTFILE='c:\\temp\\file with data.sav'.


* The following file has a single case where all values are missing.
DATA LIST LIST /x y z.
BEGIN DATA

END DATA.
VARIABLE LABELS x 'X var' y 'Y var' z 'Z var'.
VALUE LABELS y 1 'label for y=1' 3 'label for y=3'
		/z 2 'label for z=2' 4 'label for z=4'.
SAVE OUTFILE='c:\\temp\\file with labels only.sav'.


******* Start the job.
GET FILE='c:\\temp\\file with data.sav'.
N OF CASES 1.
FLIP.
RENAME VARIABLE (case_lbl=dumname).
SAVE OUTFILE='c:\\temp\\dumname.sav' /KEEP=dumname.

GET FILE='c:\\temp\\file with labels only.sav'.
FLIP.
RENAME VARIABLE (case_lbl=varname).

MATCH FILES /FILE=*
 /FILE='C:\\Temp\\dumname.sav'.
EXECUTE.

* Write syntax to rename the variable in 'file with data.sav'.
WRITE OUTFILE='c:\\temp\\rename variable.sps'
        /"RENAME VARIABLES ("dumname"="varname").".
EXECUTE.

GET FILE='c:\\temp\\file with data.sav'.
INCLUDE 'c:\\temp\\rename variable.sps'.
APPLY DICTIONNARY FROM 'c:\\temp\\file with labels only.sav'.
SAVE OUTFILE='c:\\temp\\data and labels.sav'.