Overview (BEGIN PROGRAM command)
BEGIN PROGRAM-END PROGRAM
provides the ability to integrate the capabilities of
external programming languages with IBM® SPSS® Statistics. One of the
major benefits of these program blocks is the ability to add jobwise flow control to the
command stream. Outside of program blocks, IBM SPSS Statistics can execute
casewise conditional actions, based on criteria that evaluate each case, but jobwise flow
control, such as running different procedures for different variables based on data type or level of
measurement or determining which procedure to run next based on the results of the last procedure is
much more difficult. Program blocks make jobwise flow control much easier to accomplish. With
program blocks, you can control the commands that are run based on many criteria, including:
- Dictionary information (e.g., data type, measurement level, variable names)
- Data conditions
- Output values
- Error codes (that indicate if a command ran successfully or not)
You can also read data from the active dataset to perform additional computations, update the active dataset with results, create new datasets, and create custom pivot table output.

Operations
-
BEGIN PROGRAM
signals the beginning of a set of code instructions controlled by an external programming language. - After
BEGIN PROGRAM
is executed, other commands do not execute untilEND PROGRAM
is encountered.
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. See the topic Running Commands for more information.
- Within a program block, each line should not exceed 251 bytes (although syntax generated by those lines can be longer).
- With the IBM SPSS Statistics Batch Facility (available only with IBM SPSS Statistics Server), use the -i switch when submitting command files that contain program blocks. All command syntax (not just the program blocks) in the file must adhere to interactive syntax rules.
- The keyword
PYTHON3
indicates that the Python 3 processor is used to process the Python statements.Note: Support for Python 2.x is deprecated starting with IBM SPSS Statistics 27.0.
Within a program block, the programming language is in control, and the syntax rules for that programming language apply. Command syntax generated from within program blocks must always follow interactive syntax rules. For most practical purposes this means command strings you build in a programming block must contain a period (.) at the end of each command.
Scope and limitations
- Programmatic variables created in a program block cannot be used outside of program blocks.
- Program blocks cannot be contained within
DEFINE-!ENDDEFINE
macro definitions. - Program blocks can be contained in command syntax files run via the
INSERT
command, with the defaultSYNTAX=INTERACTIVE
setting. - Program blocks cannot be contained within command syntax files run
via the
INCLUDE
command.
Using external programming languages
Use of the IBM SPSS Statistics Programmability Extension
requires an Integration Plug-in for an external language. Integration Plug-ins supported for use
with BEGIN PROGRAM-END PROGRAM
blocks are available for the Python and R
programming languages. See the topic How to Get Integration Plug-Ins for more information.
Documentation for Python scripting is available in the Scripting with Python topic. Documentation for programming in R is available in the Programming with R topic.
Resources for use with Integration Plug-ins are available on the IBM SPSS Statistics community at https://www.ibm.com/community/spss-statistics . Many of the resources are packaged as extension bundles that you can download from the Extension Hub. It is available from the menus by choosing Extensions > Extension Hub.