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. Unlike SELECT 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 (see INPUT 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 on FILTER.
  • If FILTER is specified after TEMPORARY, FILTER affects the next procedure only. After that procedure, the filter status reverts to whatever it was before the TEMPORARY command.
  • The filter status does not change until another FILTER command is specified, a USE command is specified, or the active dataset is replaced.
  • FILTER and USE are mutually exclusive. USE automatically turns off any previous FILTER command, and FILTER automatically turns off any previous USE 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, or UPDATE 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, or IMPORT command), the filter is turned off.
  • The FILTER command changes the filter status and takes effect when a procedure is executed or an EXECUTE command is encountered.