The SPSS command language
The command Processor

At the heart of SPSS is a command language processor. When you use the menu system, "behind the scene" a is prepared and when you click the OK button, SPSS executes ("runs") that command. By the way on the status bar of many SPSS Windows you are told what the processor is currently doing; it often reads IBM SPSS Statistics Processor is ready, i.e. ready to accept commands from you.

Instead of using the menu system, SPSS offers you the possibility to use the directly. [In fact for several decades, before graphical user interfaces became common, this was the only way to work with the software].

For most users it, will be convenient to learn to use the . While the menus are convenient for performing simple analysis, e.g. to produce a frequency table, menus can become quite cumbersome, for instance, when you need to transform many variables; worse, if you make a mistake, you have to start the menu, sub-menu, panel selection process all over again. On the other hand commands and command files can be saved, edited and reused.

Using means learning:

The Syntax window

Important: The syntax editor, has a number of powerful features that tend to overwhelm a beginner. We recommend turning these features off. (See ). The screenshots on this learning site have these options turned off.

Using means writing SPSS commands into a . These are created the same way as most other windows: use menu to create a new, empty syntax window or to open a with commands that have previously been saved to a file (syntax files have a .sps file name extension).

As shown, windows are text windows that let you enter and modify SPSS commands. The example shows a command that requests a frequency table for a variable named "m1".

Please note that this command works only if a variable named "m1" exists in the current working file (Data Matrix). [As these SPSS related documents are general in purpose, examples shown might need some adaptation, namely variable names.]

Commands are executed by either using one of the options from the Run menu or by highlighting them and pushing the button.

Unlike menus, using syntax also means the possibility of typos that produce error messages, explaining why a command has not been executed. Therefore you should always check the SPSS output , a window that shows, in addition to output produced by a command, the sequence of commands that has been executed, as well as error and warning messages.

To the left you see an error message, telling you that SPSS could not produce a frequency table, as the variable m1 does not exist in the current data file.

Writing commands: Basic rules

Writing commands is not difficult, write commands naturally, i.e. do not split words (names, keywords) by inserting a space.

FREQUENCIES VARIABLES=region
  /BARCHART PERCENT.
This example of a request to produce a frequency table and a barchart based on percentages will be to explain the rules below.

The following rules apply:

FREQUENCIES VARIABLES=region /BARCHART PERCENT.
FREQ VAR=REGION /BAR PER.
FRE ReGION /bar Percent.
Freq region
   / BAR    PERCENT.
All forms are equivalent....

There are of course more complex commands, with additional elements and rules

Note also that help is never far away: Click the button to get a schematic view of the current command (=current location of your cursor).

You can also use the button that calls up the Variables dialog: Select a variable from the list and click the Paste button to insert the selected variable at the current location of the cursor.

Pasting commands

A further way to add commands to a syntax window is to let SPSS do it; most command dialog boxes, as the one shown here have a Paste button: click it, instead of hitting the OK button to run the command: the command will then pasted into the , where you can further edit and run it later.

This is in fact a very handy way to type commands without a need to remember all the options, but with the advantages of the syntax windows, namely:

Remark: this is also a good way to learn command language.

Note that commands that are pasted are usually a bit lengthy with options that need not be specified as they are default options. If you had to type in the command shown here, you could also have written:

FREQUENCIES VARIABLES=m1.
FREQ VAR=m1.
FRE m1.

All versions of the command produce exactly the same table.

Final remarks

Many commands have more, often rarely used options that the ones available through menus; several more advanced features of SPSS are available through Syntax only, e.g. complex transformations, the Matrix language, complex file definitions and many more.

Related documents