Case Semantics & Transforms
Two related ideas: case semantics change which cases an analysis sees and how much each counts, and transforms create or reshape variables. Both live under the Data and Transform menus, and both are respected by every analysis automatically.
Case semantics (Data menu)
These three settings travel with every analysis, chart and transform you run. The status bar shows when any of them is active.
Select Cases
Data → Select Cases… (Ctrl+Alt+S). Restrict the analysis to a subset of
cases, for example, only participants where Age >= 60, or a random sample.
Unselected cases are filtered out of every subsequent statistic until you clear
the selection. You can choose to filter (hide) or to mark unselected cases.
The comparison value is checked against the variable's type: a numeric
variable needs a number, and a date variable needs a calendar date in
YYYY-MM-DD form (compact YYYYMMDD is accepted and canonicalized), compared
chronologically, so visit_date >= 2024-01-15 selects that day and everything
after it.
Weight Cases
Data → Weight Cases… (Ctrl+Alt+W). Give each case a frequency weight
from a variable, so a case with weight 3 counts as three observations. Used for
data stored as a frequency table. Counts, means and tests all honour the
weight. For survey (sampling) weights use
Survey Design instead. A frequency weight
reproduces cases, which is the wrong model for a sampling weight and
understates survey standard errors; the two settings are mutually exclusive.
Survey Design
Data → Survey Design… Declare the dataset's complex-survey structure: strata, clusters (PSUs) and sampling weights. The covered procedures then report design-based estimates with correct standard errors, and every other analysis says plainly that it ignored the design. The full story is on its own page: Complex Samples (Survey Designs). Under a declared design, Select Cases and Split File become domain estimation automatically (the design-correct way to analyze subgroups).
Split File
Data → Split File… (Ctrl+Alt+T). Repeat every analysis separately for
each group of a categorical variable (e.g. run all your descriptives once per
StudyZone). Output is produced per split group until you turn the split off.
Order of operations. Select narrows the cases, Weight scales their counts, and Split partitions the result into groups, and every analysis you run sees all three at once.
Transforms (Transform & Data menus)
Compute Variable
Transform → Compute Variable… (Ctrl+Shift+C). Create a new variable (or
overwrite one) from an expression. The expression language is missing-aware
and typed (number, string or date):
- Arithmetic:
+ - * /, parentheses,MOD. - Numeric functions:
SQRT,LN,LOG10,EXP,ABS,MIN,MAX, the trig family,ROUND(x[, digits]), and theSD/VARIANCEaggregates. - Logic: comparisons (
< <= > >= = ~=),AND OR NOT, andIF(cond, then, else). - String:
CONCAT,LENGTH,UPCASE,LOWCASE,LTRIM,RTRIM,SUBSTR,INDEX,REPLACE,STRING,NUMBER, and quoted literals. - Date (ISO
YYYY-MM-DD):DATE.DMY,DATE.MDY,YEAR,MONTH,DAY,DATEDIFF.
The new variable takes the type of its expression: a string expression makes a string variable, a date expression a date variable.
Example. BMI_category = IF(BMI >= 30, "Obese", IF(BMI >= 25, "Overweight", "Normal")).
Recode
Transform → Recode… (Ctrl+Shift+R). Map a variable's values into new ones,
into the same variable or a new one. Use it to collapse categories (e.g. five
education levels into three) or to band a scale variable.
Grouping a scale variable vs. histogram bins
Two things look alike but do different jobs:
- The histogram's bins slider groups a scale variable in the picture only (display, no data change). Use it to explore shape.
- A Recode into Different Variables (or Bin Variable, below, for the common numeric-cutpoints case) makes a real categorical variable (BMI → Underweight/Normal/Overweight/Obese) that crosstabs, boxplots and ANOVA can use, and that is saved with the document. Use it when the groups are part of the analysis.
The tutorial workbook's transforms module walks this exact recode end to end.
Rank Cases
Transform → Rank Cases… (Ctrl+Shift+K). Create a new variable holding each
case's rank on a chosen variable, with the usual tie-handling options.
Bin Variable
Transform → Bin Variable… (Ctrl+Shift+N). The purpose-built front end for
grouping a scale variable into a new ordinal one. Recode works for this too,
but means typing every cutpoint and label by hand. Pick a variable and a
method:
- Equal width: N groups of equal size along the value range (e.g. four 10-point-wide BMI bands).
- Equal count (quantiles): N groups with (about) the same number of cases in each, e.g. splitting into quartiles.
- Custom: your own ascending cutpoints (e.g.
18.5, 25, 30for the standard BMI categories).
A live preview shows the resolved boundaries as cut lines over a histogram of
the variable, and the generated group labels (< 18.5, 18.5 – 25, …), before
you commit. The new variable is numeric with Ordinal measure and value labels
already set: nothing left to finish in Variable View. Cutpoints are resolved
against the currently active Select Cases/Weight Cases, like every analysis.
Reshaping the dataset (Data menu)
- Sort Cases (
Ctrl+Shift+D): reorder rows by one or more variables. - Transpose (
Ctrl+Alt+P): swap rows and columns. - Merge Files (
Ctrl+Alt+M): add cases or add variables from another dataset, matched by a key (or by row position). A key that is numeric in both datasets matches by value, so1in one file meets1.0in the other; any other key matches its exact text. Each case takes the first row with its key. The status line says how many cases matched no row and how many of the file's rows matched no case (an unknown key, a blank key, a repeated key, or rows past the end of a positional join), so a join that misses is never silent. - Define Variable Properties (
Ctrl+Alt+D), Bulk Rename and Variable Sets: covered in Working with Data.
Reproducibility note
Every transform on this page is journalled: it appears in the
Syntax console as a command, so a
data-preparation pipeline can be saved and replayed on fresh data exactly.
That includes the case-semantics settings (Select Cases, Weight Cases,
Split File, as select_cases, weight_cases, split_file), Recode
(its ordered rules ride the recode command as one rule string each, in
order), Transpose, and both Merge Files modes (merge_add_cases,
merge_add_variables; the journaled command records the file's path
and the SHA-256 of its bytes, so a replay proves it merged the same
file). Bin Variable's journaled command always records the resolved
cutpoints, even for the Equal width/Equal count methods, so replaying it
later reproduces the same groups rather than silently re-deriving
different ones from changed data. A failed or cancelled dialog writes no
journal line.
Three operations remain outside the journal: Bulk Rename, Import Data
Dictionary and Define Variable Properties. If a session used one, the
saved syntax and any exported reproducibility bundle say so explicitly
(a # not replayable: note), rather than implying the journal
reconstructs the whole session.