|
I have two files with identical variables that I need to
merge. Before I do the merge I need to change the names of the
variables to make them unique. I thought to add a prefix to each variable name but there
are more than 300 variables in each file. How do I do this using syntax? Thanks for any help. Jill Meron |
|
Hi,
You could do this: begin program. import spss, spssaux vd = spssaux.VariableDict() oldnames = " ".join([var.VariableName for var in vd]) newnames = " ".join(["prefix_" + var.VariableName for var in vd]) spss.Submit("rename variables (%s = %s)." % (oldnames, newnames)) end program. But if all the var names are the same, don't you mean to use ADD FILES? Cheers!! ALbert-Jan --- On Mon, 4/27/09, Jill Meron <[hidden email]> wrote: > From: Jill Meron <[hidden email]> > Subject: Adding a prefix to all the variables in my file > To: [hidden email] > Date: Monday, April 27, 2009, 9:39 PM > > > > > > > > > > > > > > > > I have two files with identical > variables that I need to > merge. > > Before I do the merge I need to change > the names of the > variables to make them unique. > > I thought to add a prefix to each > variable name but there > are more than 300 variables in each file. > > How do I do this using syntax? > > Thanks for any help. > > Jill Meron > > > > > > > ===================== 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 Jill Meron
At 03:39 PM 4/27/2009, Jill Meron wrote:
I have two files with identical variables that I need to merge. Probably this could be done with syntax, but I'll bet the below is faster (took me about 1 minute, except for *): In Variables view, select entire Name column and Copy. Paste into column A in an Excel file. Select top cell of column B (B1). In fx window, type: =CONCATENATE("Pref",A1) This will add the prefix Pref to the variable name in cell A1. Copy the B1 cell. Select all the rest of the B column through the end of the variable list. Paste. Select entire col B (click on B at top). Copy. Select entire col C. Under Edit, click on Paste Special and select the bullet for Values. Click OK. Re-select the new list of variable names in col C. You will probably need to do this not as an entire column (selecting the C at top), but rather in one or more selections of individual cells: in top cell, click and hold mouse button to highlight. Back in SPSS, select the same number of cells under Name, and Paste. *Note: Here I got an error message saying "Variable name contains an illegal character," but re-doing it with smaller sets of cells worked fine. I assume there was some difficulty reading the underscore character or something else from Excel, but as I said, it worked with smaller sets of cells. Good Luck! Research Consultant [hidden email] Business & Cell (any time): 215 820-8100 Home: Voice and fax (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 |
| Free forum by Nabble | Edit this page |
