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
*(Q) How can I automatically remove underscores in variable names.

*(A) Posted to SPSSX-L list by Raynald Levesque on 2002/06/12.
* http://pages.infinit.net/rlevesqu/index.htm.

*GET FILE='c:\\1991\\data\\mf1991.sav'.
DATA LIST LIST / id var__1 abc_ a_b_c_d.
BEGIN DATA 
1 1 1 1
END DATA.

SAVE OUTFILE= 'c:\\temp\\tempx.sav'.
* next line is useful when you deal with a large data file.
N OF CASES 1.
flip.

string newname(a8).
COMPUTE newname=case_lbl.
LOOP IF INDEX(newname,'_')>0 .
+	COMPUTE #I = INDEX(newname,'_') .
+	COMPUTE newname=CONCAT(SUBSTR(newname,1,#I-1),SUBSTR(newname,#I+1)).
END LOOP .

DO IF case_lbl<>newname.
WRITE OUTFILE='c:\\temp\\undersco.sps' /'RENAME VARIABLE ('case_lbl'='newname').'.
END IF.

exe.

get file ='c:\\temp\\tempx.sav'.

include 'c:\\temp\\undersco.sps'.

*SAVE OUTFILE= 'c:\\1991\\data\\MF1991b.sav'.