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
OFFturns off the filter. All cases in the active dataset become available to subsequent procedures. - If
FILTERis specified without a keyword,FILTER OFFis assumed but the program displays a warning message. -
FILTERcan be specified anywhere in the command sequence. UnlikeSELECT IF,FILTERhas 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
-
FILTERperforms 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
FILTERcommand 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
FILTERis specified afterTEMPORARY,FILTERaffects the next procedure only. After that procedure, the filter status reverts to whatever it was before theTEMPORARYcommand. - The filter status does not change until another
FILTERcommand is specified, aUSEcommand is specified, or the active dataset is replaced. -
FILTERandUSEare mutually exclusive.USEautomatically turns off any previousFILTERcommand, andFILTERautomatically turns off any previousUSEcommand. - If the specified filter variable is renamed, it
is still in effect. The
SHOWcommand 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, orUPDATEcommand 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, orIMPORTcommand), the filter is turned off. - The
FILTERcommand changes the filter status and takes effect when a procedure is executed or anEXECUTEcommand is encountered.