Date: Mon, 29 Jan 2001 20:08:27 -0500
Reply-To: Raynald Levesque <rlevesque@VIDEOTRON.CA>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: Raynald Levesque <rlevesque@VIDEOTRON.CA>
Subject: Re: CHANGING VARIABLE NAME
In-Reply-To: <JGEKIENPKPNAOPNGGLDFOEFICAAA.bozena@pitt.edu>
Content-Type: text/plain; charset="iso-8859-1"
Hi Bozena!
This is an automated solution. It will change the name of any variables in
the file where the name has the format
aaaaa0n
where
a designates any alphabetic characters (and there are between 1 and 6 such
characters in the variable name)
0 is the number zero
n is any digit.
The new name is aaaaanr.
If you do not want the r in the new name, it is easy to modify the syntax
below to remove it.
Here is the syntax:
** Making a dummy file for illustration purposes.
DATA LIST /v1(F8.0).
BEGIN DATA.
1
END DATA.
NUMERIC vname01 TO vname09 vara varb varc test01 TO test09 (F8.0).
SAVE OUTFILE='c:\temp\mydata.sav'.
*** Start the job.
FLIP.
STRING nb1 nb2 (A1) newname(A8).
COMPUTE nbchar=LEN(RTRIM(case_lbl)).
COMPUTE nb1=SUBSTR(case_lbl,nbchar-1,1).
COMPUTE nb2=SUBSTR(case_lbl,nbchar).
DO IF nb1="0" and RANGE(nb2,"0","9").
COMPUTE newname=CONCAT(SUBSTR(case_lbl,1,nbchar-2),nb2,"r").
WRITE OUTFILE='c:\temp\rename.sps'
/ 'RENAME VARIABLE ('case_lbl'='newname').'.
END IF.
EXECUTE.
GET FILE='c:\temp\mydata.sav'.
INCLUDE 'C:\temp\rename.sps'.
HTH
Raynald Levesque rlevesque@videotron.ca
-----Original Message-----
From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU]On Behalf Of
Bozena Zdaniuk
Sent: Friday, January 26, 2001 1:42 PM
To: SPSSX-L@LISTSERV.UGA.EDU
Subject: CHANGING VARIABLE NAME
Hello, we are looking for automating a process of renaming hundreds of
variables. Each variable name consists of a text root and a two digit suffix
(eg., depr01, bother07, etc.). We want to change the two digit suffix to,
let's say, one digit "2" or "2r". Could some of you, syntax/programming
wizzards, send me a syntax to do it? It would help so much. Thanks a lot.
Bozena