Using Correct Full Boolean Logic to Build a Selection Statement

The Boolean "And" operator has precedence over the "Or" operator. This means that when SEER*Stat parses your selection statement, it will evaluate pairs of lines joined by "And" first, then pairs of lines joined by "Or". (If the selection statement includes more than one of the same type of operator, they will be evaluated in order of appearance, starting at the top.)

If you want to override this order of precedence, you can group one or more lines together by enclosing them in parentheses. The grouped lines will be evaluated on their own as a single True or False statement.

Example

Suppose you want to create a selection statement that will select all males that are either white or black. A common mistake is to write the following:

Incorrect:
{Race, Sex, Year Dx, Registry, County.Sex} = 'Male'
And {Race, Sex, Year Dx, Registry, County.Race recode A} = 'White'
Or {Race, Sex, Year Dx, Registry, County.Race recode A} = 'Black'

Because the "And" operator has precedence over "Or", this selection statement would actually select all white males, plus all blacks regardless of gender.

The best way to express the selection criteria you want is as follows:

Correct:
{Race, Sex, Year Dx, Registry, County.Sex} = 'Male'
And {Race, Sex, Year Dx, Registry, County.Race recode A} = 'White','Black'

The second line in the above selection statement will be satisfied by any record for which the value of the "Race recode A" variable matches any of the comma-separated values on the line -- namely, "White" or "Black".

Here is another way to achieve the same results, using the "And" and "Or" conjunctions and parentheses:

Correct:
{Race, Sex, Year Dx, Registry, County.Sex} = 'Male'
And ( {Race, Sex, Year Dx, Registry, County.Race recode A} = 'White'
Or {Race, Sex, Year Dx, Registry, County.Race recode A} = 'Black' )

Notice that this statement looks just like the original, incorrect statement, except that the last two lines are grouped by parentheses. This grouping gives them precedence, so that the expression inside the group (Race = 'White' Or Race = 'Black') is evaluated first, and the result is used to complete the "And" expression.