|
Hi All,
I have two datasets that I would like to combine (i.e. using the add variables merge).
Most of the variable names are common between the datasets.
I would like to add a prefix to each dataset prior to merging that would allow me to get past the repeating variable name problem.
Is there an easy way to do this? Or am I stuck manually adding the prefixes to 800+ variable names?
Derek
-- Dr. Derek J. Quinlan Research Project Coordinator Psychology Lecturer University of Western Ontario London, Ontario Mailing Address: Dr. Derek J. Quinlan The University of Western Ontario Westminster Hall, Suite 326E London, ON N6A 3K7 |
|
Hi Derek,
You can take the datasets to any database like SQL/ Access and write a small program to do this. You can send me the datasets with couples of sample records to do this. I can revert you with the program. Samir Paul382 Main Street ON M4C 4X8, Toronto Canada Cell - (416) 570 5696 Home - (416) 686 9958 Fax - (416) 686 9958 Skype - paulsamir.2009 From: Derek Quinlan <[hidden email]> To: [hidden email] Sent: Fri, April 9, 2010 10:59:45 AM Subject: Adding a prefix to all variable names Hi All,
I have two datasets that I would like to combine (i.e. using the add variables merge).
Most of the variable names are common between the datasets.
I would like to add a prefix to each dataset prior to merging that would allow me to get past the repeating variable name problem.
Is there an easy way to do this? Or am I stuck manually adding the prefixes to 800+ variable names?
Derek
-- Dr. Derek J. Quinlan Research Project Coordinator Psychology Lecturer University of Western Ontario London, Ontario Mailing Address: Dr. Derek J. Quinlan The University of Western Ontario Westminster Hall, Suite 326E London, ON N6A 3K7 Looking for the perfect gift? Give the gift of Flickr! |
|
In reply to this post by Derek Quinlan
Hi!
This is an old Script by Jon Peck, to add an suffix to the varibles. Open a new script, and paste this into it. Run by press F5. '----------------------------------------------------------------------- Sub Main Const SUFFIX= "_suffix" ' get variables Dim objDataDoc As ISpssDataDoc Dim objDocuments As ISpssDocuments Set objDocuments = objSpssApp.Documents Dim varList As Variant, newlist As Variant, oldlist As Variant Dim i As Long ' get the dictionary Set objDataDoc = objDocuments.GetDataDoc(0) ' Get the variables varList = objDataDoc.GetVariables (False) ' Iterate through the array of variables For i = LBound(varList) To UBound(varList) oldlist = oldlist & " " & varList(i) newlist = newlist & " " & varList(i) & SUFFIX Next i objSpssApp.ExecuteCommands "RENAME VARIABLES (" & oldlist & "=" & newlist & ").", _ False 'run cmd asynchronously End Sub '-------------------------------------- All the best Wilhelm (Wille) Landerholm Queue/STATB BOX 92 162 12 Vallingby Sweden +46-735-460000 http://www.qsweden.com http://www.statb.com QUEUE/STATB - your partner in data analysis, data modeling and data mining. 2010/4/9 Derek Quinlan <[hidden email]>
|
|
|
In reply to this post by Wilhelm Landerholm | Queue
Hi Derek,
Your problem sounded more like it would fit with suffixes than prefixes. I changed a bit in the previous script so you can set prefix. '----------------------------------------------------------------------- Sub Main Const PREFIX= "prefix_" ' get variables Dim objDataDoc As ISpssDataDoc Dim objDocuments As ISpssDocuments Set objDocuments = objSpssApp.Documents Dim varList As Variant, newlist As Variant, oldlist As Variant Dim i As Long ' get the dictionary Set objDataDoc = objDocuments.GetDataDoc(0) ' Get the variables varList = objDataDoc.GetVariables (False) ' Iterate through the array of variables For i = LBound(varList) To UBound(varList) oldlist = oldlist & " " & varList(i) newlist = newlist & " " & PREFIX & varList(i) Next i objSpssApp.ExecuteCommands "RENAME VARIABLES (" & oldlist & "=" & newlist & ").", _ False 'run cmd asynchronously End Sub '-------------------------------------- All the best Wilhelm (Wille) Landerholm Queue/STATB BOX 92 162 12 Vallingby Sweden +46-735-460000 http://www.qsweden.com http://www.statb.com QUEUE/STATB - your partner in data analysis, data modeling and data mining. 2010/4/9 Wilhelm Landerholm | Queue <[hidden email]> Hi! |
|
In reply to this post by Derek Quinlan
Another trick if you haven't got too many variables
would be to use rename for all the
vars in one file, then merge them. A lot easier if they all begin with
v.... and you use positional variable names. Not sure if you can do
it it Word, but (for the British Social Attitudes series)I used to
use EDT on the Vax in column mode and strip out columns to convert
mnemonics to positional names (which are far easier to use with the
questionnaire) and also to reverse the rename for users who
prefer mnemonics. I don't have the original syntax from 1986, but
here's an example from the 2002 European Social Survey (copied from a slide so
the colours are funny) Only trouble is, to change back, the original
variable names have to be listed in full!
rename variables
(tvtot to pplhlp = a1 to a10)
(dscrrce to dscroth = c17_1
to c17_10)
(dscrdk to dscrna =
c17_dk, c17_ref, c17_nap, c17_na)
----- Original Message -----
|
| Free forum by Nabble | Edit this page |
