At 12:53 PM 9/21/2006, Zina Karapetyan wrote:
>I have a file with over a 100 variables named Q101_ofcsp, Q102_ofceq,
>Q103_clean, Q107_cereq, Q108_load, Q109_oppor, Q110_descr, etc. I need
>to get rid of the QXXX_ part for every variable; that is to rename
>Q101_ofcsp to ofcsp, etc. Is there a way to do this in SPSS besides
>using RENAME VARIABLES? Any help would be greatly appreciated.
"Is there a way to do this in SPSS besides using RENAME VARIABLES?" No,
in syntax there isn't; either RENAME VARIABLES, or RENAME= on a SAVE,
GET, ADD FILES, or MATCH FILES. The question is (or, it may be), can
you generate those 100-odd RENAME specifications (like
"Q110_descr=descr") without writing them?
which does almost exactly what you want. It uses FLIP to get the
existing list of variables; I think that loses the string variables,
Two other ways: if you have OMS (was that SPSS 12?), you can use it to
get the data dictionary (the list of variables), and generate the
RENAME specifications from it. See my posting "Data dictionary in
SPSS", Wed, 6 Sep 2006 13:30:05 -0400. That keeps all variables.
Or, if you have SPSS 14+, Python code (BEGIN PROGRAM/ END PROGRAM) has
direct access to the data dictionary with the variable namse. It has
string functions that are plenty good enough to break the name into
pieces and build the RENAME statement; and can run the result directly,
using its spss.submit function.
Post again, if this isn't enough information.
A thought about WHETHER to do it: It looks like the prefix "QXXX_" is
something like a question number from a questionnaire; the suffix is
mnemonic, descriptive of the question; and you want to keep just the
A lot of us, when we've a dataset with a lot of variables (100 is a
lot), prefer non-mnemonic variable names like "Q110". First, "Q110"
makes it clear where the variable is in the dataset, and in what
context it arises. (What were the adjacent questions? What section of
the questionnaire was it?) Second, "Q110" will often be easier to
remember, because there are usually several equally plausible
'mnemonic' names: "descr"? "descrip"? "item_dsc"? (Long names makes
this worse, not better.) I'd consider stripping the other way: Strip
"Q110_descr" to "Q110", with "descr" in the variable label.