SPSS Dictionary
It's not informative that "a respondent has 0 on v1" unless you know what v1 and 0 refer to. Such information - what the data actually represent - is collectively know as the dictionary.
This tutorial merely explains what the SPSS dictionary is. For learning how to modify it properly (that is, by syntax), see Changing Variable Properties 1 - Introduction.
SPSS Dictionary - What is it?
- The SPSS Dictionary is a part of an SPSS data file that holds all metadata. Literally, metadata is "data about the data".
- Metadata describes the real-world meaning of values, variables and files. The best known properties of the SPSS dictionary are probably variable labels and value labels.
- Don't overlook the importance of such information. In many cases, data are worthless in the absence of correct metadata.
- The dictionary also holds more technical information on variables such as variable types and formats.
SPSS Dictionary Commands
- Some commands refer directly to SPSS' dictionary. An important one is
DISPLAY DICTIONARY.
which is extensively used by Create Dictionary Dataset. - Another example is
APPLY DICTIONARY
- which is basically what SPSS Clone Variables Tool does. - Commands for modifying variable properties also apply to the SPSS dictionary (instead of the actual data). For a handy overview, see our SPSS Dictionary Tutorials.
SPSS Dictionary - Complete Overview
Note: we tried to sort these properties from most to least important. "Optional" indicates whether a property can (technically) be absent.
Name | Applies to | Function | Importance | Optional |
---|---|---|---|---|
variable name | Variable | Variable identifier. | High | No |
Label | Variable | Normal language description of the meaning of variables. | High | Yes |
Value Labels | Value | Normal language description of the meaning of values. | High | Yes |
User Missing Values | Value | Tells SPSS which values to ignore in calculations. | High | Yes |
Type | Variable | Tells SPSS how to store values internally. | High | No |
Format | Variable | Tells SPSS how to display numeric values. | High | No |
Document | Data file | Long data file description. | Low | Yes |
Width | Variable | Maximum number of characters that values may consist of. | Low | No |
Columns | Variable | Variable's column width (as displayed on screen). | Low | No |
Variable Attribute | Variable | Descriptive tags for variables. | Low | Yes |
Datafile attribute | Data file | Data file description using arrays. | Low | Yes |
File label | Data file | Short data file description. | Low | Yes |
Align | Variable | Alignment of data values (on screen). | Low | No |
Measure | Variable | Measurement level nominal, ordinal or scale (= metric). | Low | No |
Role | Variable | The variable's supposed relation to other variables. | Low | No |
SPSS – How to Set Missing Values from Syntax?
Introduction & Practice Data File
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.)
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.)
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.)
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.)
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.)
variable role
/input married
/target income
/both q1 to q3.
SPSS – Set Variable Labels with Syntax
Managing variable and value labels without syntax is way more work than necessary. This tutorial explains how to do this more efficiently.
Changing Variable Labels in SPSS
- As with other parts of the dictionary, there's no "Paste" option for modifying variable labels.
- Be aware that manual modifications - apart from being time consuming - are not recorded in the journal file. The way to go here is using syntax.
- Changing or adding variable labels is straightforward using the
VARIABLE LABELS
command. - Although not always necessary, it is recommended to always use quotes around the label text.
- If more than one variable is labelled in a single command, use slashes (/) to separate specifications.
SPSS Variable Labels Syntax Examples
(The test data used by the syntax below are found here.)
variable labels name 'First name of respondent'.
*2. Modify (or add) two variable labels in a single command.
variable labels birthday 'Birthday of respondent'/married 'Marital status of respondent'.
Changing Value Labels in SPSS
- The
VALUE LABELS
command should be used carefully since it will first erase all value labels for a variable and then apply whatever you specify. This often made mistake is demonstrated in the syntax below. - Often,
ADD VALUE LABELS
is a better alternative for changing or adding value labels. - Note that both commands can be applied to multiple variables simultaneously. This may save a lot of time when combined with TO and ALL keywords.
- Note that the value labels themselves should be quoted. If there's a single quote in a label, you need to escape it by doubling it. Alternatively, double quotes can be used around a labels containing single quotes.
SPSS Value Labels Syntax Examples
(The test data used by the syntax below are found here.)
value labels married 1 'Never married'.
*2. Wrong way for adding/changing value labels. This removes the value label we added in the previous command.
value labels married 2 'Married'.
*3. Right way: use ADD VALUE LABELS instead of VALUE LABELS.
add value labels married 1'Never married' 3'Other' 4 'Don''t want to tell' 5 'Question skipped'.
*4. Alternative: apply all value labels in a single command.
value labels q1 q2 q3 0 'No' 1 'Yes' 2 "Don't know/not applicable".
Changing Variable Properties 4 – Width and Decimals
Changing a variable's width is rarely necessary. Nevertheless, it's good to know how when it's needed and how it's done.
Changing Variable Width in SPSS
- For string variables, width refers to how many characters a value can hold. An exception are multibyte characters as explained in SPSS Unicode Mode.
- Somewhat confusingly, "width" is not the width of a variable's column as displayed on screen, which is referred to as columns.
- For string variables, width should be increased when new values are desired that are longer than the current width. This is demonstrated by the syntax example below.
- For numeric variables, "width" refers to how many digits should be displayed. However, SPSS will often override the specified width is it's insufficient. If not,
FORMATS
can be used for increasing it.
SPSS Formats and Alter Type Syntax Examples
(The test data used by the syntax below are found here.)
formats income(f6.0).
*2. "Stefano" (7 letters) is too long for "name" (6 letters). We'll therefore increase its width to 7 characters.
alter type name(a7).
*3. Now we can change "Stefan" to "Stefano".
if name eq 'Stefan' name = 'Stefano'.
execute.
Changing Decimal Places in SPSS
- Decimal places can be changed by the
FORMATS
command. Just note that the first number refers to the width of the entire variable (including decimals) so the second number (decimals) should always be smaller. - Also, keep in mind that the actual data values will not change because of using
FORMATS
. They are merely displayed differently.
SPSS Formats Syntax Example
(The test data used by the syntax below are found here.)
formats income(f5.2).
Changing Variable Properties 3 – Type
SPSS offers several ways to change a variable's type. This tutorial will walk you through some examples.
SPSS Variable Type - Why Change it in the First Place?
- What you can do with a variable may depend on its type and - to a lesser extent - on its format.
- For example, you can extract substrings from string variables but not from numeric variables.
- For time calculations ("how many hours between ...") you'll want to use proper time variables and/or date variables.
- In some cases, you may want to use such operations on a variable that are not possible with its current type or format. In such cases, changing these is often the way to go.
Changing Variable Type in SPSS
- First note that there's really only two variable types in SPSS: string and numeric. For more on this, see SPSS Numeric Variables Basics.
- Starting from SPSS version 16, one can use ALTER TYPE in order to change a variable's type. Keep in mind that it overwrites the original variable and results in system missing values if it can't apply the requested conversion.
- However, loss of data or effort can be prevented here by working from syntax and making proper backups.
- Alternatively, use SPSS Clone Variables Tool before applying
ALTER TYPE
.
SPSS Alter Type Syntax Examples
(The test data used by the syntax below are found here.)
alter type birthday(a10).
*2. Convert back to numeric variable with date format.
alter type birthday(edate10).
SPSS String and Numeric Functions
- An alternative and more classical way for converting numeric variables into strings is with the
STRING
function. - Note that new string variables (in contrast to numeric variables) first have to be declared ("created") by the
STRING
command. - Converting string variables to numeric is done with the
NUMERIC
function.
SPSS String and Numeric Syntax Examples
(The test data used by the syntax below are found here.)
string str_q1(a1).
*2. Fill new string variable with values.
compute str_q1 = string(q1,f1)./* String function.
exe.
*3. Convert new string variable back into a (new) numeric variable.
compute num_q1 = numeric(str_q1,f1).
exe.
*4. Remove both new variables after exercise.
delete variables str_q1 num_q1.
SPSS Autorecode Command and Valuelabels Function
- Last but not least, string variables can be converted to numeric variables by the
AUTORECODE
command. - Every distinct string value is rendered as the value label of a value in a new numeric variable.
AUTORECODE
is usually applied to string variables with many duplicate values.- The reverse, passing value labels as values into a new string variable is done by the
VALUELABELS
function. - Before using it, the new string variable must first be declared with the
STRING
command.
SPSS Autorecode and Valuelabels Syntax Examples
(The test data used by the syntax below are found here.)
autorecode name
/into num_name.
*2. Declare new string variable with string command.
string str_name(a10).
*3. Fill string variable with value labels of (numeric) variable.
compute str_name = valuelabels(num_name).
exe.
*4. Delete both variables at end of exercise.
delete variables num_name to str_name.
Changing Variable Properties 2 – Names
The right way for changing variable names in SPSS is using RENAME VARIABLES
. Changing variable names manually in variable view is a bad idea because you can't keep track of what you did. This tutorial shows a better alternative.
Changing Variable Names in SPSS
- Changing variable names with syntax is straightforward with the
RENAME VARIABLES
command. - The main thing to keep in mind is that you should use parentheses when you rename more than one variable at once.
- Second, make sure that renaming variables does not result in duplicate variable names.
- Existing variable names may be used as new variable names if they're renamed themselves within the same command. So for instance,
RENAME (v1 v2 = v2 v1).
will work.
SPSS Rename Variables Syntax Examples
(The test data used by the syntax below are found here.)
rename variables name = first_name.
rename variables married= marital_status.
*2. Rename both variables back to their original names (undo previous 2 commands).
rename variables (first_name marital_status = name married).
Changing Variable Properties 1 – Introduction
A great way to start working from syntax is using "Paste" instead of "Ok". However, there's no "Paste" option for modifying most variable properties. This tutorial shows how handle that properly.
Changing Variable Properties
- Note that all variable properties (such as variable labels and value labels) are part of the SPSS dictionary.
- It is strongly recommended you use syntax in order to modify these. Why this is so important is explained in SPSS Syntax - Six Reasons you Should Use it.
- You can't "Paste" this syntax from any menu but fortunately it's very straightforward.
- This tutorial starts with creating some test data for practicing and then walks through each variable property.
- It's recommended you follow along and copy-paste-run all syntax. Don't forget to inspect your variable view after each step.
Creating Test Data
data list free/name(a6) birthday(edate10) married(f1) income(f5.0) q1 q2 q3.
begin data
Chris 15/4/1979 1 2880.5 0 1 0
Stefan 10/1/1978 0 4812.45 1 1 1
Anneke 31/3/1947 2 3438.12 1 2 2
end data.
Click on of the Properties in the Screenshot Below
Overview Changing Variable Properties
- Changing Variable Names in SPSS
- Changing Variable Type in SPSS
- Changing Variable Width in SPSS
- Changing Variable Decimals in SPSS
- Changing Variable Labels in SPSS
- Changing Value Labels in SPSS
- Setting Missing Values in SPSS
- Changing Columns in SPSS
- Changing Variable Alignment in SPSS
- Changing Variable Measure in SPSS
- Changing Variable Role in SPSS