Do you use >< for NOT EQUAL to in SAS for text?

Do you use >< for NOT EQUAL to in SAS for text?

Is Your SAS Code Lying? The Truth About "Not Equal To"

·

2 min read

The SQL syntax, when used within the SAS environment, occupies a distinct place. Its capabilities are substantial; however, its syntax can be confusing due to its intricacies., especially regarding the use of operators like <> and ><, which can cause ambiguity.

Where Things Get Tricky

  • DATA Step: In traditional DATA step code, the symbols >< represent the MIN operator. This means it returns the lower of two values in a comparison. Using it for "not equal to" would lead to incorrect results.

  • WHERE Statements and PROC SQL: SAS introduced support for SQL syntax. In WHERE statements and PROC SQL procedures, the operator <> does function as the "not equal to" comparison.

<> is a max operator, and >< is a min operator. Unless you use a WHERE clause, then <> means "not equal"...

The MIN (><) operator returns the lower of the two values. The MAX (<>) operator returns the higher of the two values.

For example, if A<B, A><B returns the A's value.

Best Practices for Clarity and Consistency

To avoid confusion and make your code more readable, here's what seasoned SAS programmers recommend:

  1. Use Explicit Operators: Use the operators specifically intended for "not equal to":

    • NE (traditional SAS operator)

    • ^= (another common option)

  2. MIN and MAX: Restrict the use of >< and <> to their intended purposes of finding the minimum and maximum values respectively.

In Summary

While you might technically get away with using >< for "not equal to" in some parts of SAS, it's not recommended. Stick to NE and ^= for clarity, accuracy, and to follow SAS best practices.

Did you find this article valuable?

Support Subhro Kr by becoming a sponsor. Any amount is appreciated!