Index

Description of files used

A syntax and a script are used to illustrate the SPSS asynchronous problem. (This is based on a 1999/08/16 post to the spss newsgroup by Kai Borgolte).

**** test.sps **** .

data list free / v1 to v3.
begin data
1 2 3
end data.

frequencies variables = v1.

* Next line creates the syntax file test.inc which includes the command: frequencies variables = v2
script 'c:\temp\test.sbs'.
* We then include (run) that file to get the frequencies of v2.
include 'c:\temp\test.inc'.
* we erase the file since we no longer need it.
erase file = 'c:\temp\test.inc'.

frequencies variables = v3.
' **** c:\temp\test.sbs **** .

Sub Main

Open "c:\temp\test.inc" For Output As #1
Print #1, "frequencies variables = v2 ."
Close #1

'A message to the user confirming that the file has been created.
MsgBox "test.sbs is running, test.inc has been written"

End Sub

Demonstration of the problem

The above example involves a syntax calling a script. Note that the asynchronous problem occurs also when a script calls a syntax.

Possible work around

Pre version 12

Fabrizio's script SyntaxScript.sbs was written to solve that problem. Note that the original script enters in an endless loop when a syntax file has hard spaces at the end. The following version SyntaxScript2.sbs solves that problem.

Ensure that the test.sps syntax is the designated syntax window, load and execute SyntaxScript2 and you will see that the syntax test.sps performs as expected. All 3 frequencies are produced. It is convenient to add a custom made button to the toolbar and attach the SyntaxScript2 to it. It becomes very simple to invoke the script whenever necessary.

Note that there are limitations to the script. In particular when the script call passes arguments to the script, a different method must be used by the script to read the argument.

In some cases, the executable by Alexis-Michel Mugabushaka can also be used to circumvent the asynchronous problem. See the executable section of the script page.

Version 13

The introduction of the HOST COMMAND provided new ways to work around the asynchronous problem. See the the second edition of SPSS Programming and Data Management which is available as a free download from SPSS website.

Version 14

With version 14, Python Scripts executed within a syntax file runs synchronously with the syntax, so the problem is now solved. See Self adjusting code for examples of synchronous execution using Python.