HerfstkleurenHelpdesk IBM SPSS Statistics 20

Introduction Sample size Table design Graph design Syntax Testing Links SPSS Statistics 20

The syntax This page is based on the online SPSS help

We have used several webpages from the SPSS help to summarize what the SPSS syntax is about and how you can create it.
That text is © Copyright IBM Corporation 1989, 2011.

Layout, pictures, examples and additional remarks are created by Gé Groenewegen.

Working with Command Syntax

The command language allows you to save and automate many common tasks. It also provides some functionality not found in the menus and dialog boxes.
Most commands are accessible from the menus and dialog boxes. However, some commands and options are available only by using the command language (see the percentile example below).
The command language also allows you to save your jobs in a syntax file so that you can repeat your analysis at a later date or run it in an automated job.

A syntax file is simply a text file that contains commands. While it is possible to open a syntax window and type in commands, it is often easier if you let the software help you build your syntax file by pasting command syntax from dialog boxes or by copying syntax from the output log.

Detailed command syntax reference information is available through the SPSS help system.


Pasting Syntax from Dialog Boxes

The easiest way to build a command syntax file is to make selections in dialog boxes and paste the syntax for the selections into a syntax window. By pasting the syntax at each step of a lengthy analysis, you can build a job file that allows you to repeat the analysis at a later date or run an automated job with the Production Facility.

The following example comes from the independent samples t-test output we performed elsewhere on this site. We fill in the dialog box and next click on the Paste-button:

paste syntax for t-test

A separate syntax window now opens. It contains the SPSS command lines to execute the t-test we defined in the dialog box above.

syntax window for t-test

In the syntax window you can run the pasted syntax, edit it, and save it in a syntax file.


Copying Syntax from the Output Log

You can build a syntax file by copying command syntax from the log that appears in the Viewer.

log text in output

Each command appears in the Viewer along with the output from the analysis.
In the syntax window you can run the pasted syntax, edit it, and save it in a syntax file.

The following example comes from the independent samples t-test output we performed elsewhere on this site. If you remember that we performed a t-test for differences in average age between females and males, then this piece of syntax will be clear to you.

t-test syntax from output log
You will recognize this syntax from the paste technique explained above.
You can copy this text from the output, paste it into an open syntax window and use it there.
SPSS will automatically recognize the pasted text as valid syntax and adjust its layout and coloring to the correct syntax options.

Below you see a syntax window with the t-test command created by both methods described here. As you can see they are identical.

result of two ways of creating syntax


Using the Syntax Editor

The Syntax Editor provides an environment specifically designed for creating, editing, and running command syntax. The Syntax Editor features:

  • Auto-Completion. As you type, you can select commands, subcommands, keywords, and keyword values from a context-sensitive list. You can choose to be prompted automatically with the list or display the list on demand.
  • Color Coding. Recognized elements of command syntax (commands, subcommands, keywords, and keyword values) are color coded; so, at a glance, you can spot unrecognized terms. Also, a number of common syntactical errors - such as unmatched quotes - are color coded for quick identification.
  • Breakpoints. You can stop execution of command syntax at specified points, allowing you to inspect the data or output before proceeding.
  • Bookmarks. You can set bookmarks that allow you to quickly navigate large command syntax files.
  • Auto-Indentation. You can automatically format your syntax with an indentation style similar to syntax pasted from a dialog box.
  • Step Through. You can step through command syntax one command at a time, advancing to the next command with a single click.


An example to experiment with syntax

The example below shows you a piece of syntax that is created through the editor. In the first picture you see how we are building an Explore command where we want percentiles to be calculated.
Through the dialog box for Explore we have only one technique available. The syntax shows that SPSS has in total five different algorithms to calculate percentiles. If you are familiar with them and their differences you can choose your favorite option.

But of course, if you are no expert, you will most likely trust on the default settings that were picked by the SPSS development team. See also our page on the Explore command in the analysis section of this site.

building syntax

And now the result of five versions of the percentiles subcommand:

five times explore percentile

If you are curious what it does, first open the data file percentile_experiment.sav and next this syntax five times explore percentile.sps.
Then run the syntax and study the output.

If you are really curious about the differences between these five percentile algorithms, experiment with other data for the variable V1.
For example you can use {1, 2, ..., 36, 37} or {2, 4, 6, 8, 10, 12}.
And of course check out the syntax and the underlying algorithms through the online SPSS help. Look for the manual called "IBM SPSS Statistics Algorithms.pdf".


Last modified 30-10-2012

© Jos Seegers, 2009; English version by Gé Groenewegen.