Overview (FILTER command)
FILTER
is
used to exclude cases from program procedures without deleting them
from the active dataset. When FILTER
is in effect, cases with a zero or missing value for the specified
variable are not used in program procedures. Those cases are not actually
deleted and are available again if the filter is turned off. To see
the current filter status, use the SHOW
command.
Basic Specification
The basic
specification is keyword BY
followed
by a variable name. Cases that have a zero or missing value for the
filter variable are excluded from subsequent procedures.
Syntax Rules
- Only one numeric variable can be specified. The variable can be one of the original variables in the data file or a variable computed with transformation commands.
- Keyword
OFF
turns off the filter. All cases in the active dataset become available to subsequent procedures. - If
FILTER
is specified without a keyword,FILTER OFF
is assumed but the program displays a warning message. -
FILTER
can be specified anywhere in the command sequence. UnlikeSELECT IF
,FILTER
has the same effect within an input program as it does outside an input program. Attention must be paid to the placement of any transformation command used to compute values for the filter variable (seeINPUT PROGRAM
).
Operations
-
FILTER
performs case selection without changing the active dataset. Cases that have a zero or missing value are excluded from subsequent procedures but are not deleted from the file. - Both system-missing and user-missing values are treated
as missing. The
FILTER
command does not offer options for changing selection criteria. To set up different criteria for exclusion, create a numeric variable and conditionally compute its values before specifying it onFILTER
. - If
FILTER
is specified afterTEMPORARY
,FILTER
affects the next procedure only. After that procedure, the filter status reverts to whatever it was before theTEMPORARY
command. - The filter status does not change until another
FILTER
command is specified, aUSE
command is specified, or the active dataset is replaced. -
FILTER
andUSE
are mutually exclusive.USE
automatically turns off any previousFILTER
command, andFILTER
automatically turns off any previousUSE
command. - If the specified filter variable is renamed, it
is still in effect. The
SHOW
command will display the new name of the filter variable. However, the filter is turned off if the filter variable is recoded into a string variable or is deleted from the file. - If the active dataset
is replaced after a
MATCH FILES
,ADD FILES
, orUPDATE
command and the active dataset is one of the input files, the filter remains in effect if the new active dataset has a numeric variable with the name of the filter variable. If the active dataset does not have a numeric variable with that name (for example, if the filter variable was dropped or renamed), the filter is turned off. - If the active dataset is
replaced by an entirely new data file (for example, by a
DATA LIST
,GET
, orIMPORT
command), the filter is turned off. - The
FILTER
command changes the filter status and takes effect when a procedure is executed or anEXECUTE
command is encountered.