Note that this problem is completely resolved with SPSS version 14 by the advent of Python scripting.


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 which includes the command: frequencies variables = v2
script 'c:\temp\'.
* We then include (run) that file to get the frequencies of v2.
include 'c:\temp\'.
* we erase the file since we no longer need it.
erase file = 'c:\temp\'.

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

Sub Main

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

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

End Sub

Demonstration of the problem

  • Save the above script and syntax in c:\temp\. The first time you run the syntax,
    1. Frequencies of v1 is printed.
    2. The message from the script confirms that the has been written.
    3. Frequencies of v2 is not printed.
    4. Frequencies of v3 is printed.
  • When you look at the log, you will see that was not found and that, hence, it was not erased (since it did not exist when that line of syntax was executed).
  • However if you look in the c:\temp folder, you will see the file. It was created after the ERASE command was run.
  • Now if you run the syntax again, without manually erasing the file, the program will work as expected, the frequencies of all 3 variables will be produced.

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

Version 12 and earlier

Fabrizio's script 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 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 VB Programs 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.

Version 14 and above

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.

Related pages