SPSS FILTER – Simple Tutorial

FILTER is an SPSS command for deactivating cases. Inactive cases are excluded from analysis and some data modifications (most notably AGGREGATE). Note that the status bar informs you whether a filter variable is in effect or not.

SPSS Filter On

Notice “Filter On” in the status bar.

SPSS Filter – Basic Use

Any regular variable can be specified as a filter variable.* When a filter variable is in effect, all cases having either a

  1. Zero value or
  2. system missing value or
  3. user missing value

on the filter variable are (temporarily) deactivated. Similarly to WEIGHT and SPLIT FILE, FILTER has three main commands:

  1. FILTER BY […]. switches a filter variable on. If a filter is already in effect, it can be used to set a different variable as the active filter.
  2. SHOW FILTER. shows which variable is the active filter variable.
  3. FILTER OFF. switches the filter variable off. After doing so, all cases in the data are active.

How Do I Get a Filter Variable?

Ideally, a filter variable has a value of 1 for cases you want to be visible and 0 for cases you want to deactivate. Such a variable may already exist in your data but you usually have to create it yourself. Keep in mind that it’s just a normal variable. A great way for doing so is using Compute A = B = C. If you’re not comfortable with that, use IF or RECODE. We recommend using a short variable name that indicates its role as a filter, for example filt_…. Add a variable label describing which cases it should select. It’s fine to have multiple filter variables in your data but you can use only one at the time as the active filter.

SPSS Filter – Caveats

  • As mentioned earlier, FILTER does not only affect your output. It affects some data modifications as well, most notably AGGREGATE.
  • When a filter is in effect, you’ll notice that inactivated cases will have a strikethrough through their $casenum. Somehow, this strikethrough is absent for cases having a user missing value on the filter variable. We discovered this while writing this tutorial and believe it to be a bug in SPSS’ FILTER command that has been present since at least version 15. We’d be grateful if anybody could (dis)confirm our presumption on this.

SPSS FilterStrikethrough when filter in effect. Note the absence for the case with a user missing value.

SPSS Filter Syntax Example

*1. Create some test data.

data list free/v1.
begin data
0 ” 9999 -100 -.001 .001 100
end data.

*2. Display three decimals to show difference small values and zero.

formats v1(f4.3).

*3. Specify user missing value.

missing values v1(9999).

*4. Filter.

filter by v1.

*5. Inspect which variable is used as filter.

show filter.

*6. Aggregate affected by filter.

aggregate outfile * mode addvariables
/case_count = n.

*7. Switch filter off.

filter off.