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
- 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, 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.
Strikethrough when filter in effect. Note the absence for the case with a user missing value.
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.