Jump to content

How to use SPSS/Using syntax

From Wikiversity

Opening a syntax file

[edit | edit source]

In order to open a syntax sheet with which to work on, you can navigate with your mouse through the file path File>New>Syntax or you can simply click paste when trying to run any statistical test. If you click paste, then the test you were trying to run won't display (like an output window popping up). Instead, you will be presented with the syntax workspace with syntax that is typed. Keep in mind that a syntax file can only be opened by using the file path File>Open>Syntax.

What is syntax?

[edit | edit source]

Syntax is a file type. Syntax is a text file which can store many SPSS commands. Syntax files are very handy. They can be used as a method of saving all of your changes to a dataset and can easily be followed by others. If anyone wants to know what changes you made to a dataset, it is easier for you to create a syntax file and type/paste in all of the statistical tests and changes you are doing to the dataset. Syntax is used to refer to the type of file that it is and a command is the text that you type into the syntax file. You might also notice some lines stating that a certain dataset will be used for the syntax file. Generally, this is just stating which open dataset the syntax will be using currently to run the commands. It's important to have the right dataset open before you highlight and run your statistics. Otherwise, you might generate a bunch of unknown errors.

To get syntax into a syntax file, you can:

  • Use the drop-down menus (e.g., Analyze) to set up analyses, and then click "Paste" instead of "OK"
  • Click on a line and type, edit, copy etc. syntax commands directly into the syntax file

As SPSS users become more experienced, directly editing the syntax becomes more efficient than navigating through the pull-down menus.

Once you have a syntax workspace up, you can highlight and run the syntax by pressing the green button that looks like a play button or type in the syntax file to generate a new statistical test, table, or report.

Examples

[edit | edit source]

Here are two examples of syntax commands:

desc vars = age.

freq vars= sex.

The first command will create Descriptive Statistics for the variable Age. The second comment will create Frequencies for the variable Sex.

There are sometimes many different ways to run a statistical test or tell SPSS to run the same syntax.

Next it is followed by the "=" to suggest what variables to look at. Next is the variable name that you want to analyze. In this case, Age and Sex are the variables being used in the analyses. You must always use the same variable name that is in the dataset. If you mistype or use the wrong name for a variable you will most likely see an error message.

Syntax commands end with a full-stop. Be sure to end a command with a period - this is a common error. If you don't, you will see an error message when you try to run the command. Some other different commands that you might encounter when using spss are:

See also

[edit | edit source]