Logical functions

  • Each argument to a logical function (expression, variable name, or constant) must be separated by a comma.
  • The target variable for a logical function must be numeric.
  • The functions RANGE and ANY can be useful shortcuts to more complicated specifications on the IF, DO IF, and other conditional commands. For example, for non-missing values, the command

    SELECT IF ANY(REGION,"NW","NE","SE").

    is equivalent to

    SELECT IF (REGION EQ "NW" OR REGION EQ "NE" OR REGION EQ "SE").

RANGE. RANGE(test,lo,hi[,lo,hi,..]). Logical. Returns 1 or true if test is within any of the inclusive range(s) defined by the pairs lo, hi. Arguments must be all numeric or all strings of the same length, and each of the lo, hi pairs must be ordered with lo <= hi. Note: For string values, results can vary by locale even for the same set of characters, since the national collating sequence is used. Language order, not ASCII order, determines where certain characters fall in the sequence.

ANY. ANY(test,value[,value,...]). Logical. Returns 1 or true if the value of test matches any of the subsequent values; returns 0 or false otherwise. This function requires two or more arguments. For example, ANY(var1, 1, 3, 5) returns 1 if the value of var1 is 1, 3, or 5 and 0 for other values. ANY can also be used to scan a list of variables or expressions for a value. For example, ANY(1, var1, var2, var3) returns 1 if any of the three specified variables has a value of 1 and 0 if all three variables have values other than 1.

See Treatment of missing values in arguments for information on how missing values are handled by the ANY and RANGE functions.