BETWEEN Condition

Selects rows where column values are within a range of values.

Syntax

sql-expression <NOT> BETWEEN sql-expression
AND sql-expression

Required Argument

sql-expression

is described in sql-expression.

Details

  • The SQL expressions must be of compatible data types. They must be either all numeric or all character types.
  • Because a BETWEEN condition evaluates the boundary values as a range, it is not necessary to specify the smaller quantity first.
  • You can use the NOT logical operator to exclude a range of numbers. For example, you can eliminate customer numbers between 1 and 15 (inclusive) so that you can retrieve data on more recently acquired customers.
  • PROC SQL supports the same comparison operators that the DATA step supports. For example:
       x between 1 and 3
       x between 3 and 1
       1<=x<=3
       x>=1 and x<=3