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 (June 2011)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Wed, 1 Jun 2011 07:21:40 -0600
Reply-To:   ViAnn Beadle <vab88011@gmail.com>
Sender:   "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:   ViAnn Beadle <vab88011@gmail.com>
Subject:   Re: adding a prefix to all variables
Comments:   To: John F Hall <johnfhall@orange.fr>
In-Reply-To:   <003401cc202b$734d2560$59e77020$@fr>
Content-Type:   multipart/alternative;

Except if you have to do it 100 times

From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] On Behalf Of John F Hall Sent: Wednesday, June 01, 2011 1:14 AM To: SPSSX-L@LISTSERV.UGA.EDU Subject: Re: adding a prefix to all variables

Nice one! Researcher time lost = money wasted: researcher time gained = more (and better?) research.

John F Hall

johnfhall@orange.fr

www.surveyresearch.weebly.com <http://surveyresearch.weebly.com/>

From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] On Behalf Of Allan Lundy, PhD Sent: 01 June 2011 01:40 To: SPSSX-L@LISTSERV.UGA.EDU Subject: Re: adding a prefix to all variables

Listers, An exceeding inelegant but surefire solution that I use all the time:

Select all variable names from the Variable View. (Click on top name and with the button still depressed, pull mouse down -- highlighting will continue off bottom). Right-click and Copy. Paste to Column A in Excel. In Col 1B, enter =CONCATENATE("prefix",A1). Copy this and paste to all cells below. Copy all Column B and Paste Special Values to Col C. Copy Col C cells from first to last and paste back into the SPSS variable names that are still highlighted.

Though it seems complex, it takes about 60 seconds. It has the advantage of showing all the new names so you can glance at them and be sure none are misleading. Also, it is easy to work out somewhat different prefixes -- like to number them in order (=concatenate("Var",row(),A1). Finally, after doing this once or twice, you never have to look up how to do it again.

Sometimes brainless solutions to problems work just as well as smart ones and take much less time. Allan

At 11:36 AM 5/20/2011, you wrote:

So easy with Python:

begin program. import spss, spssaux varlist = spssaux.VariableDict().variables newnames = ['pre_' + v for v in varlist] cmd = "RENAME VARIABLES (%s=%s)" % (" ".join(varlist), " ".join(newnames)) spss.Submit(cmd) end program.

Jon Peck Senior Software Engineer, IBM peck@us.ibm.com new phone: 720-342-5621

From: Bruce Weaver <bruce.weaver@hotmail.com> To: SPSSX-L@LISTSERV.UGA.EDU Date: 05/20/2011 08:15 AM Subject: Re: [SPSSX-L] adding a prefix to all variables Sent by: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>

I was thinking about a macro too, but got hung up on trying to hand it the variables with a "V1 TO Vlast" list. But I think you have to list all variables, as Paul has done here.

You could also make the prefix a variable that you hand to the macro when you call it. E.g.,

define !addprefix (prefix=!tokens(1) / invar=!cmdend). !do !i !in (!invar). rename variables(!i=!concat(!prefix,!i)). !doend. !enddefine.

!addprefix prefix = T2 invar=var1 var2 var3. descriptives all.

Cheers, Bruce

Paul Oosterveld wrote: > > With the following macro you can add any prefix to the variables you list > in the macro call. > > Paul Oosterveld > > data list free > /var1 var2 var3. > begin data. > 1 2 3 > 1 2 3. > end data. > > define !addprefix (invar=!cmdend). > !do !i !in (!invar). > rename variables(!i=!concat("T2",!i)). > !doend. > !enddefine. > > !addprefix invar=var1 var2 var3. > descriptives all. >

----- -- Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/

Allan Lundy, PhD Research Consulting Allan.Lundy@comcast.net

Business & Cell (any time): 215-820-8100 Home (8am-10pm, 7 days/week): 215-885-5313 Address: 108 Cliff Terrace, Wyncote, PA 19095 Visit my Web site at www.dissertationconsulting.net <http://www.dissertationconsulting.net/>

===================== 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 SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD


[text/html]


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