SPSS tutorials


SPSS Syntax Introduction

SPSS” Syntax Editor window is the second of SPSS’ three main windows. As we'll see in a minute, this is where we run commands for opening files, editing data, generating results and, finally, saving files. The Syntax Editor is recognized by an orange icon SPSS Data Editor Window Icon in its left top corner. SPSS Data Editor Title Bar

SPSS Syntax - First Encounter

We recommend you follow along with this example by downloading employees.sav. Next, run SPSS without opening the data file. Now, two obvious ways for opening a data file are double clicking it or dragging it into the Data Editor window. However, we'll now show a completely different approach. This may seem overly complicated at first but it will eventually save you a lot of time and effort.
Right. Navigating to File SPSS Menu Arrow New SPSS Menu Arrow Syntax opens a new syntax window. A faster alternative is clicking the New Syntax icon (or for older SPSS versions) that you may find on one of the toolbars.

SPSS Syntax - Paste

At this point, you could type the SPSS command for opening the data file in the Syntax Editor window. But what exactly are you supposed to type? Well, this is where SPSS’ menu comes in handy.
We'll navigate to File SPSS Menu Arrow Open SPSS Menu Arrow Data and then navigate to the data file we want to open. Now, clicking Paste instead of Open pastes the desired command into our Syntax Editor window.

SPSS Open Data Dialog

After doing so, the Syntax Editor will look something like the screenshot below.Most users will see some toolbars right under the menu bar but we chose to leave those out of the screenshot. The data file does not open (yet). SPSS Open Data with Syntax

Running SPSS Syntax

So far, we generated a command for opening our data file but we didn't carry it out yet. For running SPSS syntax, first select the command(s) you'd like to run. You can do so by using your mouse or one of several shortkey. An especially nice shortkey here is F2, which selects the entire command in which your cursor is located.
Next, press CTRL + r for running the command(s) that you selected in the previous step. Alternatively, you can click the green arrow for running selected commands.
Note that running the pasted syntax indeed opens the downloaded data file.

SPSS Syntax Files

After opening a data file, we typically want to inspect, edit or analyze our data. The right way for doing so is adding the desired commands to the end of the Syntax Editor window by pasting or typing them. Now here comes the trick: when we're done, we save the contents of the Syntax Editor. This results in an SPSS syntax file or .sps file after its file name extension.
SPSS syntax files are technically plain text files. This mean that we can't use different font sizes, font types, boldface or italics in them. The good news is that you don't need SPSS to open syntax file: Notepad (or, preferably, notepad++) or even a web browser will do as you can see by clicking here.

SPSS Syntax - Final Notes

Using and saving syntax is the single best SPSS practice. From your syntax file you'll know exactly what you did, in which order you did it and you'll know it for sure. On top of that, you can adjust and rerun all your syntax in a matter of seconds if desired. More reasons for using syntax are discussed in SPSS Syntax - Six Reasons you Should Use it.
Great. So now that we've explored two of SPSS’ three main windows, let's move on to the final one: SPSS Output Viewer window.

Previous tutorial: SPSS Data Editor Window

Next tutorial: SPSS Output Viewer Window

Let me know what you think!

*Required field. Your comment will show up after approval from a moderator.

This tutorial has 23 comments