WHERE-Expression Processing |

Syntax |

You can combine or modify WHERE expressions by using the logical operators (also called Boolean operators) AND, OR, and NOT. The basic syntax of a compound WHERE expression is as follows:

WHERE where-expression-1 logical-operator where-expression-n ;

Symbol | Mnemonic Equivalent |
---|---|

& | AND |

! or | or ¦ | OR |

^ or ~ or ¬ | NOT |

Processing Compound Expressions |

When SAS encounters a compound WHERE expression (multiple conditions), the software follows rules to determine the order in which to evaluate each expression. When WHERE expressions are combined, SAS processes the conditions in a specific order:

For a complete discussion of the rules for evaluating compound expressions, see Order of Evaluation in Compound Expressions.

Using Parentheses to Control Order of Evaluation |

Even though SAS evaluates logical operators in a specific order, you can control the order of evaluation by nesting expressions in parentheses. That is, an expression enclosed in parentheses is processed before one not enclosed. The expression within the innermost set of parentheses is processed first, followed by the next deepest, moving outward until all parentheses have been processed.

For example, suppose you want a list of all the Canadian sites that have both SAS/GRAPH and SAS/STAT software, so you issue the following expression:

where product='GRAPH' or product='STAT' and country='Canada';

The result, however, includes all sites that license SAS/GRAPH software along with the Canadian sites that license SAS/STAT software. To obtain the correct results, you can use parentheses, which causes SAS to evaluate the comparisons within the parentheses first, providing a list of sites with either product licenses, then the result is used for the remaining condition:

where (product='GRAPH' or product='STAT') and country='Canada';

Copyright © 2010 by SAS Institute Inc., Cary, NC, USA. All rights reserved.