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
*(Q) I am about to merge three huge data sets. Every dataset contains hundreds of
	vars. The var names are identical except for the prefix "tn". For example,
	var names of dataset no.1 start with"t1" t1abc, t1xyz, t1sps....
* var names of dataset no.2 start with"t2" t2abc, t2xyz, t2sps....
* var names of dataset no.3 start with"t3" t3abc, t3xyz, t3sps....
* How can I rename the vars of datsets nos. 2 and 3, so that they will begin
	with "t1", e.g. "t1abc" (former "t3abc"), too?

*(A) Posted to SPSSX-L by rlevesque@videotron.ca on 2002/01/23.
* http://pages.infinit.net/rlevesqu/index.htm.


DATA LIST FREE /t2c, t2sal, t2age, t2sex1, t2school,t2v12345.
BEGIN DATA
85 95 5 87 100 1
90 100 1 25 25 2
END DATA.
LIST.
SAVE OUTFILE='c:\\temp\\mydata.sav'.

* Be sure you have a backup copy of your data file before running this.
* Next lines ensures no error will occur when there are more than 32,000 variables
	in the data file (Thanks to H. Maletta for this suggestion).
N OF CASES 1.
FLIP.
STRING newname(A8).
COMPUTE newname=CONCAT("t1",SUBSTR(case_lbl,3)).
WRITE OUTFILE 'c:\\temp\\temp.sps' 
   /"RENAME VARIABLE ("case_lbl"="newname").".
EXE.

GET FILE='c:\\temp\\mydata.sav'.
INCLUDE 'c:\\temp\\temp.sps'.