Skip to content
Tutorials Center
My learning

Topics

Lesson 12 of 39 ยท Data Preparation

SPSS Select Cases, Split File and Weight Cases Explained

Analyze a subset or compare groups in SPSS: Select Cases with filter or delete, SELECT IF and TEMPORARY, Split File layered or separate output, and Weight Cases by frequency.

Not every analysis should use every case. You might want only adults, or the results for each region side by side, or a table whose rows hold counts rather than individual people. SPSS has three tools in the Data menu for this: Select Cases, Split File and Weight Cases. They are powerful, and because they stay on until you switch them off, they are the most common source of "why is my N so small?" confusion. The status bar always shows which are active.

Select Cases

Data > Select Cases... offers these choices in the Select group:

Option Meaning
All cases Turns selection off
If condition is satisfied Uses cases for which a logical expression is true (the If... button)
Random sample of cases Approximate percentage, or an exact number from the first n cases
Based on time or case range A range of case numbers (First Case to Last Case)
Use filter variable Cases where a chosen variable is neither 0 nor missing

The Output group decides what happens to the unselected cases:

  1. Filter out unselected cases (default): they stay in the file but are ignored; they appear crossed out (a diagonal slash through the case number). SPSS creates a variable filter_$ with 1 for selected and 0 for others.
  2. Copy selected cases to a new dataset: you name the new dataset.
  3. Delete unselected cases: they are removed permanently once you save.

In the syntax for the filter option:

TEXT
USE ALL.
COMPUTE filter_$=(age >= 18 AND MISSING(age) = 0).
FILTER BY filter_$.
EXECUTE.

Later, switch it off with FILTER OFF. followed by USE ALL.. For a permanent deletion the command is:

TEXT
SELECT IF (age >= 18).

SELECT IF deletes the cases from the active dataset. If you then save over the file, those cases are gone for good. Prefer a filter or a copy to a new dataset, and run SELECT IF only on a dataset you can rebuild.

Conditions in the If dialog

The expression follows the same rules as compute variable: comparison operators, AND/OR/NOT, ANY(), RANGE(). Examples: gender = 2, age >= 18 & age < 65, ANY(region, 1, 3), NOT MISSING(income). Cases whose condition is missing are not selected.

Python Stand-in: filter vs delete

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.

TEMPORARY

Put TEMPORARY. before SELECT IF (or SAMPLE, N OF CASES, WEIGHT) and the change applies only to the next procedure, then the full file returns. It is the safest way to run a single analysis on a subset.

TEXT
TEMPORARY.
SELECT IF (region = 3).
FREQUENCIES VARIABLES=satis.

After the FREQUENCIES run, all cases are back. Do not put COMPUTE between TEMPORARY and the procedure expecting it to survive: transformations after TEMPORARY are also temporary.

Random samples

Random sample of cases > Sample... picks about 10% (approximately) or exactly 50 cases out of the first 200. This is for exploration, testing syntax on big files or splitting data into training and test sets. Use SET SEED 2026. before sampling in syntax to make it repeatable.

Split File

Data > Split File... repeats every later analysis separately for each group of a variable, such as gender or region.

  • Analyze all cases, do not create groups: off (default).
  • Compare groups: one table per procedure with the groups stacked in it (layered side by side).
  • Organize output by groups: a separate set of tables for each group, one after another.
  • Groups Based on: choose one or more variables.
  • Sort the file by grouping variables (default ticked): SPSS needs the data sorted by the split variables; if it is not, you get several tables for one group.
TEXT
SORT CASES BY gender.
SPLIT FILE LAYERED BY gender.
DESCRIPTIVES VARIABLES=age income.
SPLIT FILE OFF.

SPLIT FILE LAYERED BY is the compare-groups form; SPLIT FILE SEPARATE BY organizes output by groups. When the split is on, the status bar shows Split File On. Always end with SPLIT FILE OFF., because a forgotten split silently breaks every later analysis (a t test with a split file runs once per group instead of between groups).

Split File is perfect for "describe each group" tasks. For a test comparing groups, do not split; use the group as a grouping variable.

Python Stand-in: split file runs the analysis once per group

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.

Weight Cases

Data > Weight Cases... tells SPSS to count each case as if it appeared several times. Choose Weight cases by and move a numeric Frequency Variable into the box. The status bar then shows Weight On.

Two uses:

  1. Aggregated data. A table of counts such as gender by smoker with a count column can be analyzed as if each row were repeated count times. Without weighting, SPSS would treat 4 rows as 4 people.
  2. Survey weights that make the sample resemble the population. For complex designs prefer the Complex Samples module, since normal procedures treat weights as frequencies and inflate sample size (and so exaggerate significance).
TEXT
WEIGHT BY count.
CROSSTABS /TABLES=gender BY smoker /STATISTICS=CHISQ.
WEIGHT OFF.

Cases with a missing, zero or negative weight are excluded. Weights may be fractional, but then totals can be non-integers and some tests round or complain.

Python Stand-in: what a frequency weight does

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.

The checklist before every analysis

  1. Is the filter on? (status bar: Filter On)
  2. Is Split File on?
  3. Is Weight on?
  4. What is the N in the output, and does it match what you expect?

If an unexpected one is on, reset it (FILTER OFF. USE ALL. SPLIT FILE OFF. WEIGHT OFF.), then run again. Put these four commands at the top of every analysis syntax file.

Common mistakes

  • Leaving a filter, split or weight on and analyzing the wrong cases.
  • Using SELECT IF and saving over the only copy of the data.
  • Splitting the file and then running a test that needs all cases.
  • Weighting survey data with decimals in the normal procedures and trusting the p-values.
  • Forgetting the file must be sorted by the split variable.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. How does Select Cases > Filter out unselected cases differ from Delete unselected cases?

    Filtered cases remain and can be restored with Select All; deleted cases are removed from the active dataset.
  2. 2. What does TEMPORARY do before SELECT IF?

    TEMPORARY limits the transformation to the next procedure; afterward the full file returns.
  3. 3. You want mean income for each region in one run. Which tool fits?

    Split File repeats analyses for each group of the split variable.
  4. 4. A table has columns gender and count, where count is the number of people. How do you analyze it correctly?

    Weighting by the frequency variable makes each row count that many times.

Summary

  • Select Cases restricts the analysis: filter, copy to a new dataset or delete; use TEMPORARY. for one-off subsets.
  • Split File repeats analyses per group (layered or separate); sort first and turn it off afterward.
  • Weight Cases treats each row as several cases; zero and missing weights drop cases.
  • Check the status bar and the N in output before trusting any result.

Next: Combining and Restructuring Files