Selecting Records Using IF Phrases

How to:

The IF phrase selects records to be included in a report, and offers a subset of the functionality of WHERE. For a list of supported IF operators, see Using Operators in Record Selection Tests.

Tip: Unless you specifically require IF syntax (for example, to support legacy applications), we recommend using WHERE.

Syntax: How to Select Records Using the IF Phrase

IF fieldname operator literal [OR literal]

where:

fieldname
Is the field you want to test (the test value).
operator
Is the type of selection operator you want. Valid operators are described in Operators Supported for WHERE and IF Tests.
literal
Can be the MISSING keyword (as described in Missing Data Tests) or alphanumeric or numeric values that are in your data source, with the word OR between values.

Note that all literals that contain blanks (for example, New York City) and all date and date-time literals must be enclosed within single quotation marks.

Note: The IF phrase alone cannot be used to create compound expressions by connecting simple expressions with AND and OR logical operators. Compound logic requires that the IF phrase be used with the DEFINE command, as described in Using Expressions. You can accomplish this more easily with WHERE. See Using Compound Expressions for Record Selection.

Example: Using Multiple IF Phrases

You can use as many IF phrases as necessary to define all your selection criteria, as illustrated in the following example:

TABLE FILE EMPLOYEE
PRINT EMP_ID LAST_NAME
IF SALARY GT 20000
IF DEPARTMENT IS MIS
IF LAST_NAME IS CROSS OR BANNING
END

All of these criteria must be satisfied in order for a record to be included in a report. The output is:

EMP_ID     LAST_NAME
------     ---------
818692173  CROSS