LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (September 2006)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Thu, 21 Sep 2006 14:06:17 -0400
Reply-To:   Richard Ristow <wrristow@mindspring.com>
Sender:   "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:   Richard Ristow <wrristow@mindspring.com>
Subject:   Re: renaming variables - deleting the first part of the name
Comments:   To: Zina Karapetyan <zina.karapetyan@remudaranch.com>
In-Reply-To:   <EBDC7E1030363A4AA4A6DD5E974E7A5002EE5CA9@scorpex02.wickenb urg.remuda.com>
Content-Type:   text/plain; charset="us-ascii"; format=flowed

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?

See http://www.spsstools.net/Syntax/LabelsAndVariableNames/ChangeCharacterAtBeginningOfEachVarNames.txt which does almost exactly what you want. It uses FLIP to get the existing list of variables; I think that loses the string variables, though.

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 mnemonic part.

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.


Back to: Top of message | Previous page | Main SPSSX-L page