Skip to content
Tutorials Center
My learning

Topics

Lesson 6 of 39 ยท Interface and Data

Defining Variables in SPSS Variable View: Name, Type, Label, Measure

Define SPSS variables properly: naming rules, numeric, string and date types, width and decimals, labels, measure, role, alignment, plus copying properties and entering data by hand.

When you open a new, empty data file, SPSS has no idea what you will record. Variable View is where you tell it. Each row describes one variable, and each column is one property. Setting these carefully is the difference between output that reads "Q7 B" and output that reads "Satisfaction with delivery". It also makes later procedures behave correctly.

Switch to Variable View with the tab at the bottom of the Data Editor. A new variable is created when you type a name in the first empty row of the Name column.

The columns of Variable View

Column Purpose
Name The short identifier used in dialogs and syntax
Type Numeric, String, Date, Dollar, etc.
Width Total characters displayed (for strings, the maximum length)
Decimals Digits after the decimal point shown
Label A longer description shown in output
Values Value labels, such as 1 = Female
Missing Codes treated as user-missing
Columns Display width of the column in Data View
Align Left, right or center
Measure Scale, Ordinal or Nominal
Role Input, Target, Both, None, Partition or Split

Naming variables

A good name is short, descriptive and legal. The rules:

  • up to 64 bytes (in many versions this is 64 characters for English text);
  • must start with a letter, @, # or $ (avoid the last two: # makes a scratch variable, $ is for system variables);
  • may contain letters, digits, periods and underscores, but no spaces; it cannot end with a period and should not end with an underscore;
  • must be unique, case-insensitive (Age and age clash);
  • must not be a reserved word: ALL, AND, BY, EQ, GE, GT, LE, LT, NE, NOT, OR, TO, WITH.

Pick a convention and stick to it. Common styles:

  • q1_age, q2_gender: numbered questionnaire items with a hint;
  • satis_deliv, satis_price: a shared stem lets you use the TO keyword: satis_deliv TO satis_price selects every variable between them in file order.
Python Stand-in: is this a legal variable name?

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Variable type

Click the grey button in the Type cell to open the Variable Type dialog.

Type Use
Numeric Numbers: ages, scores, codes
Comma / Dot Numbers displayed with thousands separators
Scientific notation Very large or small numbers
Date Dates in a chosen format (dd-mmm-yyyy, mm/dd/yyyy...)
Dollar Currency-formatted
Custom currency Your own currency formats
String Text. You choose a maximum length (Characters)
Restricted Number Numbers that keep leading zeros (like ZIP codes)

Rules of thumb:

  • Store categories as numeric codes (1, 2, 3) with value labels, not as text. Numeric codes sort predictably and work in every procedure.
  • Use string only for true text (names, comments, IDs with letters). Many procedures cannot use string variables, and string comparisons are case sensitive.
  • Dates are stored as seconds since 14 October 1582 internally. The Date type formats them; you need it for date arithmetic (DATEDIFF, DATESUM).
  • Width is the total digits shown, including the decimal point. A value that does not fit displays as asterisks (****) in Data View, though it is still stored correctly. Increase the width or reduce decimals.
  • Keep Decimals at 0 for counts and codes. Decimals only change the display; SPSS stores full precision.

Labels and values

The Label can be up to 256 characters. It is what output shows, so write it for the reader: "Satisfaction with delivery (1 = very low, 5 = very high)". Keep labels consistent in tense and wording across the file.

The Values column (value labels) is covered in the next lesson, value labels and missing values. In syntax, labels come from VARIABLE LABELS and VALUE LABELS:

TEXT
VARIABLE LABELS gender 'Gender of respondent'
  satis_deliv 'Satisfaction with delivery'.
VALUE LABELS gender 1 'Female' 2 'Male' 3 'Other'.

Notice that a quoted label can span several variables in one command, separated by a new line and no period until the end.

Measure and Role

Measure tells SPSS the level (Scale, Ordinal, Nominal). SPSS sets a guess when it creates the variable: numeric variables with many distinct values become Scale, strings become Nominal. Check every variable, because the guess is often wrong for coded variables (a column of 1/2/3 may be marked Scale). Charts and some procedures depend on it. To fix many at once: select several rows in the Measure column, set one and copy and paste it, or use Data > Set Measurement Level for Unknown to mark variables where it is not set.

Role is used mainly by newer procedures that preselect inputs and targets. The default Input is fine for the classic tests in this course.

Entering a small dataset by hand

Suppose you record 5 customers: name, age, plan (Basic or Plus) and satisfaction (1 to 5).

  1. In Variable View, define four rows:
    • custname, Type String, width 20, Label "Customer name", Measure Nominal.
    • age, Type Numeric, width 3, decimals 0, Label "Age in years", Measure Scale.
    • plan, Type Numeric, width 1, decimals 0, Label "Subscription plan", Values 1 = Basic, 2 = Plus, Measure Nominal.
    • satis, Numeric, 1, 0, Label "Overall satisfaction", Values 1 = Very low ... 5 = Very high, Measure Ordinal.
  2. Go to Data View and type values. Press Tab to move right, Enter to move down.

The same thing in syntax:

TEXT
DATA LIST FREE / custname (A20) age plan satis.
BEGIN DATA
"Ana" 34 2 5
"Ben" 29 1 3
"Chloe" 41 2 4
"Dev" 23 1 2
"Eli" 52 2 5
END DATA.

DATA LIST FREE reads values separated by spaces; (A20) means a string of up to 20 characters. Compared with typing into the grid, syntax is repeatable.

Python Stand-in: a variable dictionary and a summary

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Copying properties

Defining 40 questionnaire items one by one is slow. Shortcuts:

  • Copy and paste cells between rows in Variable View (select a cell, Ctrl+C, select others, Ctrl+V).
  • Data > Copy Data Properties... copies labels and value labels from another dataset or file to the active one.
  • Data > Define Variable Properties... scans selected variables, lists their values with counts, and lets you label values and set missing codes in one pass. It is excellent for imported data.
  • Utilities > Variables shows a dictionary of any variable.
  • File > Display Data File Information > Working File lists every variable's properties in the Output Viewer. Paste it into documentation.

Common mistakes

  • Giving a variable a name with a space, then wondering why SPSS replaces it with an underscore.
  • Leaving codes as strings ("1", "2"), which prevents numeric analyses.
  • Hiding decimals and then believing the stored value is rounded; it is not.
  • Forgetting to set the Measure, so charts and tables treat an ordinal rating as a scale.
  • Using Q1, Q2, ... as variable names with no labels, then losing track of what they ask.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which is a legal SPSS variable name?

    Names must start with a letter, cannot contain spaces and cannot be a reserved word such as ALL.
  2. 2. A numeric column shows ***** in Data View. What is the most likely cause?

    Asterisks mean the number does not fit the display width. The stored value is unchanged.
  3. 3. Why store categories as numeric codes with value labels instead of strings?

    Numeric codes are robust (no spelling or case differences) and can be used by most procedures, while labels give readable output.
  4. 4. Which menu command scans values and helps you label them for many variables at once?

    Define Variable Properties lists observed values and lets you set labels, missing values and measure in one pass.

Summary

  • Variable View defines each variable: Name, Type, Width, Decimals, Label, Values, Missing, Columns, Align, Measure, Role.
  • Names must be unique, start with a letter, contain no spaces and avoid reserved words.
  • Use numeric codes with value labels for categories; reserve strings for real text.
  • Always check and set Measure; labels make output readable.
  • Define Variable Properties, Copy Data Properties and syntax commands (VARIABLE LABELS, VALUE LABELS) speed up the work.

Next: Importing Data from Excel, CSV and Text Files