Date: Fri, 9 Apr 2010 17:27:21 +0200
Reply-To: Wilhelm Landerholm | Queue <wl@qsweden.com>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: Wilhelm Landerholm | Queue <wl@qsweden.com>
Subject: Re: Adding a prefix to all variable names
In-Reply-To: <m2jedee9a001004090759gf5f9d48di701070eded0eff48@mail.gmail.com>
Content-Type: multipart/alternative;
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
>
>
[text/html]