Date: Thu, 14 Aug 1997 21:49:13 +0100
Sender: "SPSSX(r) Discussion" <SPSSX-L@UGA.CC.UGA.EDU>
From: mark oldfield <markoldfield@COMPUSERVE.COM>
Organization: Kent Probation Service
Subject: Re: Script for changing formats in String Variables - QUERY?
Content-Type: text/plain; charset=us-ascii
> Hello Evrybody
> Iv'e come across a little problem here. I wish for various reasons,
> mainly for automatic mergging of files to standardise the length of the
> string variables in several files. As the amount of variables is quite
> large I have no desire to point and click at each string variable to
> change its length.
> So far I have written the following script.
> Sub Main
> Dim objDocuments As ISpssDocuments
> Dim objDataDoc As ISpssDataDoc
> Dim objSpssInfo As ISpssInfo
> Set objDocuments = objSpssApp.Documents
> 'Open data document if one is already open
> If objDocuments.DataDocCount <> 0 Then
> Set objDataDoc = objDocuments.GetDataDoc(0)
> 'Now change all string variables to length = 60
> Set objSpssInfo = objSpssApp.SpssInfo
> Dim varCount As Integer
> varCount = objSpssInfo.NumVariables
> For i = o To varCount -1
> If objSpssInfo.VarType(i) = 1 Then
> 'Change string length to 60
> 'MsgBox("FORMATS " +
objSpssInfo.VariableAt(i) + " (A60) .")
> objSpssApp.ExecuteCommands ("FORMATS " +
> " (A60) .", True)
> objSpssApp.ExecuteCommands ("EXECUTE.", True)
> End If
> End If
> End Sub
> which just goes thorugh each variable, checking to see if it is a string
> If it is then I want to change the lentgh to, say, 60.
> However when invoking the FORMATS command which is the command which
> apperas if
> you use the point and click method of chanign the string length I get
> the error
> FORMATS congen1 (A60) .
> >Warning # 4837 in column 9. Text: CONGEN1
> >The width of a string format must match the width of the string variable.
> >The correct width has been substituted.
> On a bit of digging I found an old message from the newsgroups from
> Daivid Marso which suggests
> making a new variable of the length required, copying the old one
> across, deleting the old
> one and then renaming the new one with the old name.
> This however leaves the new variable at the end of the file. I wish to
> maintain the position of
> my string variables while changing the format.
> Can anyone help me here. Is there another way of re-formating string
> variable lengths,
> or a method to position a new variable in a file at a specified point.
> Many thanks for any help
> Craig Gould, PhD Student.
> e-mail : email@example.com
> www : http://www.inn.org/
You could create the new string variables of the length you want, copy
the old variable to it, rename them both and then, when you save the
file, use the 'KEEP' command, listing your variables in the order you
want them to appear in the file.