Date: Thu, 14 Aug 2008 15:58:32 +0200
Reply-To: Eero Olli <firstname.lastname@example.org>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: Eero Olli <email@example.com>
Subject: Re: rename all variables in a dataset
Content-Type: text/plain; charset="us-ascii"
A text-editor based solution:
There has been a discussion concerning renaming all variables in a
dataset. And the solutions have been elegant macros or python scripts.
These are of course the best option if one needs to do the same
procedure repeatedly on a file that changes from time to time.
However, my worksituation, where nobody else would be able to read the
macros or python codes, does suggest that sometimes a less elegant
low-tech solution is called for.
I would run the following line from the SPSS syntax editor.
Which gives an output like this:
I would then cut and paste this list into my editor in a new empty file
(I use UltraEdit32, but all proper editors intended for writing syntax
I put my editor in column mode, and mark all lines. This allows me to
write the same text simultaneously on every line. Thus it does not
really matter if I am writing one, two or thousand lines of syntax
Then I just type in the beginning of the lines "RENAME VARIABLES ("
Then I jump to the end of lines and type "="
Then I paste the variable names again in one long column
Then I jump to the end of lines and type "_suffix )."
Then I do a search and replace to remove all extra spaces before
"_suffix", if the variable names are of varying length.
In the end I will have a syntax that looks like this:
RENAME VARIABLES (Var1 = Var1_suffix).
RENAME VARIABLES (Var2 = Var2_suffix).
RENAME VARIABLES (Var3 = Var3_suffix).
I would then copy and paste this back to the SPSS syntax editor, where I
run and save it for documentation.
The advantages of the editor based solution, as I see it, are
1) it is a fast solution, because it is easy to remember and quick to
implement. Renaming 100 variables takes perhaps 10 more seconds than
just one variable. (In lorenzos example, after writing the syntax for
the first set of RENAMES, all one needs to do is to do a search and
replace for each suffix, to create new versions of the same
2) it is easy to select and control which variables are renamed.
3) it requires only minimum level of skill. the rest of the staff will
be able to figure out what has happened, even if I am not there.
4) having variable names present in transformations, makes it possible
to track changes to a variable across many syntax files. Any
professional quality texteditor will allow for a search in many *.sps
files for "variablename" and present the results as a list lines
containing "variablename". This makes it easy to figure out what
happens to a piece of information across several transformations. This
makes it also possible to implement changes of variable names across all
my syntax files at once, to ensure that they are all consistent.
5) better portability of the syntax. This can be a problem if somebody
else is using the syntax or if I myself want to use the same syntax
after a few years on a different computer using different version of
SPSS and python.
6) writing many lines at once keeps the typoes down to a minimum, and if
they are there, they are easy to find, as they effect every line of the
1) If a variable is added into the orginal file, I need to add one line
of code to the RENAME VARIABLES, too.
2) it is easy to forget to do 1). This is the best reason for using a
macro or a python solution, in my view.
3) It creates lots of code (which sometimes is an advantage as it
usually easy to read).
the Equality and Anti-discrimination Ombud
firstname.lastname@example.org +47 2405 5951
POB 8048 Dep, N-0031 Oslo, Norway
To manage your subscription to SPSSX-L, send a message to
LISTSERV@LISTSERV.UGA.EDU (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
For a list of commands to manage subscriptions, send the command