Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

script - won't run from syntax

126 views
Skip to first unread message

Josh Sacco

unread,
Apr 21, 2002, 8:42:30 PM4/21/02
to
Hi - I'm using SPSS 10.1.0. When I run a script from the menus it
works great. When I run the script using syntax all I get is "running
script..." in the status bar, and SPSS hangs -- the script never
finishes running. The script is at c:\string.sbs and I use the
following syntax to run it:
script 'c:\string.sbs'.

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

Raynald Levesque

unread,
Apr 22, 2002, 8:33:26 PM4/22/02
to

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

Raynald Levesque

unread,
Apr 23, 2002, 7:36:14 AM4/23/02
to
On 21 Apr 2002 17:42:30 -0700, jo...@msu.edu (Josh Sacco) wrote:

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

0 new messages