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.
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 <derek.james.quinlan@gmail.com>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