Hi Listers,
I have two phases of data collection using a matched instrument (Phase1.sav and Phase2.sav). Now I want to merge the two files to create a matched dataset. What I want to do is add a prefix to all variables in Phase2.sav (as they are at present they are named the same in both datasets) so for example I want to add 'P2' to all variables in Phase2.sav. Is there any way to automate this or do I have to do it by hand? I am using V18 with patches - but am not using python Thanks Muir Muir Houston, HNC, BA (Hons), M.Phil., PhD, FHEA Social Justice, Place and Lifelong Education Research School of Education University of Glasgow 0044+141-330-4699 R3L+ Project - Adult education in the light of the European Quality Strategy http://www.learning-regions.net/ GINCO Project - Grundtvig International Network of Course Organisers http://www.ginconet.eu/ ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (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 |
Administrator
|
If you would settle for .1 and .2 suffixes for the phase 1 and 2 variables, you could do this (untested):
add files file = "C:\MyFolder\phase1.sav" / file = "C:\MyFolder\phase2.sav" / in = p2 . exe. compute phase = p2 + 1. Then restructure with CASESTOVARS, using variable PHASE as the index.
--
Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." PLEASE NOTE THE FOLLOWING: 1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. 2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/). |
In reply to this post by Muir Houston-3
I would copy the p2 variable names to Excel, then, in the column next to
the variable names, concatenate "p2" to the front of the variable names. Like so: If the first row in the column is cell A1, in cell B1, type: ="p2"&A1 Then extend the series to the end. Then copy new new variable names back to SPSS. On 5/19/2011 6:23 AM, Muir Houston wrote: > Hi Listers, > I have two phases of data collection using a matched instrument > (Phase1.sav and Phase2.sav). Now I want to merge the two files to create > a matched dataset. What I want to do is add a prefix to all variables in > Phase2.sav (as they are at present they are named the same in both > datasets) so for example I want to add 'P2' to all variables in > Phase2.sav. Is there any way to automate this or do I have to do it by > hand? > I am using V18 with patches - but am not using python > > Thanks > Muir > > Muir Houston, HNC, BA (Hons), M.Phil., PhD, FHEA > Social Justice, Place and Lifelong Education Research > School of Education > University of Glasgow > 0044+141-330-4699 > > R3L+ Project - Adult education in the light of the European Quality > Strategy > http://www.learning-regions.net/ > > GINCO Project - Grundtvig International Network of Course Organisers > http://www.ginconet.eu/ > > ===================== > To manage your subscription to SPSSX-L, send a message to > [hidden email] (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 -- W. Joel Schneider Associate Professor of Psychology Illinois State University http://my.ilstu.edu/~wjschne/ ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (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 |
In reply to this post by Bruce Weaver
Hi Bruce,
I do not mind what they are called - so will give your solution a go - also thanks to Joel Schnieder for his Excel solution
Muir
Dr Muir Houston
Social Justice, Place and Lifelong Education Research
School of Education
College of Social Sciences
University of Glasgow
0141-330-4699
R3L+ Project - Adult education in the light of the European Quality Strategy http://www.learning-regions.net/ GINCO Project - Grundtvig International Network of Course Organisers http://www.ginconet.eu/ From: SPSSX(r) Discussion on behalf of Bruce Weaver Sent: Thu 19/05/2011 15:20 To: [hidden email] Subject: Re: adding a prefix to all variables If you would settle for .1 and .2 suffixes for the phase 1 and 2 variables, |
In reply to this post by Muir Houston-3
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. ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (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 |
Administrator
|
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
--
Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." PLEASE NOTE THE FOLLOWING: 1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. 2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/). |
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 [hidden email] new phone: 720-342-5621 From: Bruce Weaver <[hidden email]> To: [hidden email] Date: 05/20/2011 08:15 AM Subject: Re: [SPSSX-L] adding a prefix to all variables Sent by: "SPSSX(r) Discussion" <[hidden email]> 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 [hidden email] http://sites.google.com/a/lakeheadu.ca/bweaver/ |
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: Research Consulting [hidden email] 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 ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (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 |
Nice one! Researcher time lost = money wasted: researcher time gained = more (and better?) research. John F Hall From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Allan Lundy, PhD
So easy with Python: Allan Lundy, PhD ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (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 |
In reply to this post by Allan Lundy, PhD
if you use something like this in excel: "("&a1&"=prefix_"&a1&")"you can generate Spss syntax in excel so at least you leave a trail of what you did. You only need to add 'rename variables' and a dot at the end. If you paste it straight into the data editor, your work is not entirely reproducible.
Albert-Jan ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From: "Allan Lundy, PhD" <[hidden email]> To: [hidden email] Sent: Wed, June 1, 2011 1:40:05 AM Subject: Re: [SPSSX-L] 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:
Allan Lundy, PhD |
In reply to this post by John F Hall
Except if you have to do it 100 times From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of John F Hall Nice one! Researcher time lost = money wasted: researcher time gained = more (and better?) research. John F Hall From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Allan Lundy, PhD
So easy with Python: Allan Lundy, PhD ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (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 |
Free forum by Nabble | Edit this page |