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.
Notice “Filter On” in the status bar.
SPSS Filter - Basic Usage
Any regular variable can be specified as a filter variable.By “regular variable” we mean all variables that are not a scratch variable or a system variable. When a filter variable is in effect, all cases having either a
- Zero value or
- a system missing value or
- a user missing value
on the filter variable are (temporarily) deactivated. Similarly to
FILTER has three main commands:
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.
SHOW FILTER.shows which variable is the active filter variable.
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,
FILTERdoes not only affect your output. It affects some data modifications as well, most notably
- 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'
FILTERcommand that has been present since at least version 15. We'd be grateful if anybody could (dis)confirm our presumption on this.
SPSS Filter Syntax Example
data list free/v1.
0 '' 9999 -100 -.001 .001 100
*2. Display three decimals to show difference small values and zero.
*3. Specify user missing value.
missing values v1(9999).
filter by v1.
*5. Inspect which variable is used as filter.
*6. Aggregate affected by filter.
aggregate outfile * mode addvariables
/case_count = n.
*7. Switch filter off.