Any ideas why the script can't be run from syntax?
I obtained the script from the SPSS website -- it's to convert all the
strings to 60 charachters long. The script is below.
'Begin Description
'This script will replace all string variables with
'new string variables of length 60. A constant at the
'beginning of the file allows a different length to be chosen.
'End Description
Sub Main
'the following constant will be used as the
'new length of all String variables
Const newLength As Integer = 60
Dim objDocuments As ISpssDocuments
Dim objDataDoc As ISpssDataDoc
Dim objSpssInfo As ISpssInfo
Dim varName As String
Dim varList As String
Set objDocuments = objSpssApp.Documents
'Open data document if one is already open
If objDocuments.DataDocCount <> 0 Then
Set objDataDoc = objDocuments.GetDataDoc(0)
objDataDoc.Visible=True
'Now change all string variables to length = 60
Set objSpssInfo = objSpssApp.SpssInfo
Dim varCount As Integer
varCount = objSpssInfo.NumVariables
If varCount = 0 Then
End
End If
For i = 0 To varCount - 1
varName = objSpssInfo.VariableAt(i)
If objSpssInfo.VarType(i) = SpssDataString Then
'Make new string variable of length newLength
objSpssApp.ExecuteCommands ("STRING newVar(A" & Format(newLength)
& ").", True)
objSpssApp.ExecuteCommands ("COMPUTE newVar = " & varName & " .",
True)
objSpssApp.ExecuteCommands ("EXECUTE.", True)
objSpssApp.ExecuteCommands ("RENAME VARIABLES " & varName & " =
temp" & Format(i) & ".", True)
objSpssApp.ExecuteCommands ("RENAME VARIABLES newVar = " & varName
& ".", True)
objSpssApp.ExecuteCommands ("EXECUTE.", True)
End If
'Add old variable name to list of variables
varList = varList & " " & varName
Next
objSpssApp.ExecuteCommands ("MATCH FILES FILE=* /KEEP " & varList,
True)
objSpssApp.ExecuteCommands ("EXECUTE.",True)
End If
End Sub
The following syntax will do it for you:
* Sample data to illustrate the method.
DATA LIST LIST /num1(F8.0) alpha1(A10) num2(F8.0) alpha2(A8).
BEGIN DATA
1 aaaaaaaaa 12 bbbbbb
END DATA.
LIST.
SET ERRORS=none.
* Replace 5 in next line by the desired length.
STRING tmp(a5).
DO REPEAT var=ALL.
COMPUTE tmp=var.
COMPUTE var=tmp.
END REPEAT PRINT.
SET ERRORS=listing.
EXECUTE.
HTH
Raynald Levesque rlev...@videotron.ca
Visit My SPSS Pages: http://pages.infinit.net/rlevesqu/index.htm
Sorry, the code I posted yesterday does not do the job.
The approach described in
http://pages.infinit.net/rlevesqu/MacroTutorial.htm#Version3
could be used.
Regards