When working with SPSS, specifying missing values correctly is often an essential step in analyzing data. This tutorial demonstrates how to set missing values the right way.
Setting Missing Values in SPSS
- Perhaps unsurprisingly, missing values can be specified with the
MISSING VALUES
command. - A thing to note, however, is that missing values can be specified for multiple variables at once.
- Second, missing values may be specified as a range. If a range is used, a single discrete missing value can be added to it.
- The syntax example below gives some examples of this.
SPSS Missing Values Syntax Examples
(The test data used by the syntax below are found here.)
*1. Specifying 4 and 5 as missing values for "married".
missing values married(4,5).
*2. Specify a range (1,000,000 and upwards) as missing values for "income".
missing values income (1000000 thru hi).
*3. Specify 2 as missing value for variables q1 through q3.
missing values q1 to q3 (2).
missing values married(4,5).
*2. Specify a range (1,000,000 and upwards) as missing values for "income".
missing values income (1000000 thru hi).
*3. Specify 2 as missing value for variables q1 through q3.
missing values q1 to q3 (2).
Changing Columns in SPSS
- Columns refers to how wide a variable column is displayed on screen. It can be set by the
VARIABLE WIDTH
command. - This may be confusing since this does not refer to the "width" (length) of a variable as explained under variable width.
- Although setting columns doesn't affect your actual data, it's of minor importance. For the sake of completeness, the syntax example below demonstrates the command.
SPSS Variable Width Syntax Example
(The test data used by the syntax below are found here.)
*Set columns = 50 for q1 through q3..
variable width q1 to q3 (50).
variable width q1 to q3 (50).
Changing Variable Alignment in SPSS
- Variable alignment refers to how data values are aligned within their columns. The options are "left", "centered" or "right".
- As in MS Excel, the default settings are left for string variables and right for numeric variables.
- These can be overridden by the
VARIABLE ALIGNMENT
command as demonstrated below.
SPSS Variable Align Syntax Example
(The test data used by the syntax below are found here.)
*Set Variable Alignment = center for q1 through q3.
variable alignment q1 to q3 (center).
variable alignment q1 to q3 (center).
Changing Measurement Levels in SPSS
- On a personal note, we feel the Measure property for setting measurement levels is rather useless. This is something that users - not software - should be aware of and take into account when analyzing data.
- Regretfully, some commands (most notably
CTABLES
) are actually affected by the measurement levels as specified by the user. - In this case, the
VARIABLE LEVEL
command can be used for setting them to nominal, ordinal or scale (for metric variables).
SPSS Variable Level Syntax Example
(The test data used by the syntax below are found here.)
*Set measurement level to scale for "birthday", ordinal for "married" and nominal for q1 through q3.
variable level birthday(scale) married(ordinal) q1 to q3 (nominal).
variable level birthday(scale) married(ordinal) q1 to q3 (nominal).
Changing Roles in SPSS
- Just as with Measure, we feel the "Role" property is rather useless and had perhaps better be removed from SPSS.
- For the sake of completeness, it can be modified as demonstrated below.
SPSS Variable Role Syntax Example
(The test data used by the syntax below are found here.)
*Set role to input for "married", target for "income" and both for "q1" through "q3".
variable role
/input married
/target income
/both q1 to q3.
variable role
/input married
/target income
/both q1 to q3.
THIS TUTORIAL HAS 13 COMMENTS:
By Lee Lee on April 17th, 2015
Re: Changing Columns in SPSS
You said that "setting columns doesn't affect your actual data, it's of minor importance". However, it matter especially if you're merging files. If the properties of key variables are not the same, the files will not merge. It didn't work for me that's why I had to figure out how to set the columns in syntax which your site was found to be quite useful, so, Thank YOU!!
By Ruben Geert van den Berg on April 19th, 2015
Thanks for your comment! However, you seem to confuse "columns" and "width" as shown in variable view.
The confusing thing here is that in syntax, VARIABLE WIDTH refers to columns, not width. Indeed, width has to be equal for string variables over data sources in order to merge them.
If columns differ, however, the data sources will merge fine. This syntax example demonstrates this.
Insofar as I know, variable type and width are the only two properties that have to be consistent over data sources in order to merge them.
By Joe Drew on October 5th, 2015
Under the Category of "Setting Missing Values in SPS" you state "A thing to note, however, is that missing values can be specified for multiple variables at once"
It would help if you would provide the commands or examples on precisely how to do this?
By Ruben Geert van den Berg on October 6th, 2015
The last line of the syntax following this statement gives an example:
missing values q1 to q3 (2).
specifies 2 as a missing value for variables q1 through q3.
By Katherine Wang on March 3rd, 2016
Sometimes I want to recode user missing values (e.g. don't know) to be valid (e.g. when I discovered that a huge proportion answered "don't know" and I'd like to include this answer category in my output). How can I use syntax to un-do the "missing values" command? Thanks!