Note: The Python function sys.exit() is not supported for use within a program block.
The first program block in a session should start with the Python function import spss,
which imports the spss module, providing access to the functions in the Python Integration
Package for IBM® SPSS® Statistics. For more information, see the topic Python Functions
and Classes in Chapter 2 on p. 15.
Subsequent program blocks in the same session do not require import spss, and it is
silently ignored if the module has already been imported.
Example
DATA LIST FREE /var1.
BEGIN DATA
1
END DATA.
DATASET NAME File1.
BEGIN PROGRAM PYTHON.
import spss
File1N=spss.GetVariableCount()
END PROGRAM.
DATA LIST FREE /var1 var2 var3.
BEGIN DATA
1 2 3
END DATA.
DATASET NAME File2.
BEGIN PROGRAM PYTHON.
File2N=spss.GetVariableCount()
if File2N > File1N:
message="File2 has more variables than File1."
elif File1N > File2N:
message="File1 has more variables than File2."
else:
message="Both files have the same number of variables."
print message
END PROGRAM.
The first program block contains the import spss statement. This statement is not required
in the second program block.
The first program block defines a programmatic variable, File1N, with a value set to the
number of variables in the active dataset.
Prior to the second program block, a different dataset becomes the active dataset, and the
second program block defines a programmatic variable, File2N, with a value set to the
number of variables in that dataset.
Since the value of File1N persists from the first program block, the two variable counts can
be compared in the second program block.
Syntax Rules
Within a program block, only statements recognized by the specified programming language
are allowed.
Command syntax generated within a program block must follow interactive syntax rules.