String variables in logical expressions

String variables, like numeric variables, can be tested in logical expressions.

  • String variables must be declared before they can be used in a string expression.
  • String variables cannot be compared to numeric variables.
  • If strings of different lengths are compared, the shorter string is right-padded with blanks to equal the length of the longer string.
  • The magnitude of strings can be compared using LT, GT, and so on, but the outcome depends on the sorting sequence of the computer. Use with caution.
  • User-missing string values are treated the same as nonmissing string values when evaluating string variables in logical expressions. In other words, all string variable values are treated as valid, nonmissing values in logical expressions.