Data management: variables, missing values, compute, recode, select
Variable View holds the metadata that makes output readable — labels, value labels, missing codes and measure level — and the Transform and Data menus create, recode, filter and sort data without changing your original file.
How do I define a variable?
| Column | What it does |
|---|---|
| Name | Short name used in commands: starts with a letter; letters, digits, _ . @ # $; no spaces. |
| Type | Numeric or String. Changing string → numeric turns non-numbers into system-missing (StatLab warns). |
| Width / Decimals | Display only; calculations use full precision. |
| Label | Readable name shown in output. |
| Values | Value labels, one per line: 1 = Male. Toggle “Value labels” above the grid to see them in Data View. |
| Missing | Up to three discrete codes and/or a range (e.g. 90 thru 99). These cases are left out of every analysis; blank cells are “system-missing”. |
| Measure | Scale, ordinal or nominal — a reminder of which procedures make sense. |
How do I compute a new variable?
Transform → Compute variable. Examples: MEAN(q1, q2, q3, q4, q5) (mean of the valid items), post - pre, LN(income), RND(age / 10) * 10. Operators: + − * / ** and comparisons = <> < <= > >= with AND, OR, NOT. Functions: ABS SQRT LN LG10 EXP RND TRUNC MOD; MEAN SUM MIN MAX SD VARIANCE NVALID NMISS (these skip missing arguments); MISSING SYSMIS ANY RANGE; UPCASE LOWER LENGTH CONCAT SUBSTR TRIM NUMBER STRING. Any missing operand in arithmetic gives a missing result. The optional IF condition limits the cases that are computed.
How do I recode?
Transform → Recode into different variables (keeps the original — recommended) or into same variables. Rules are written in parentheses, first match wins: (LO thru 29 = 1) (30 thru 49 = 2) (50 thru HI = 3) (ELSE = SYSMIS). Reverse-score a 1–5 item: (1=5)(2=4)(3=3)(4=2)(5=1). Old values can be a value, a list, a range, MISSING, SYSMIS or ELSE; new values a number, 'text', SYSMIS or COPY.
How do I analyse only some cases?
Data → Select cases with a condition such as gender = 2 AND age >= 18. “Filter” keeps the other cases (a 0/1 variable filter_$ is created and the status bar shows the filter); “Delete” removes them permanently (asks for confirmation). Choose “All cases” to switch the filter off.
How do I sort?
Data → Sort cases by one or two variables, ascending or descending. Missing values sort first.