Logic Operators

The basic operators are:

Operation

Syntax

Equality

=, eq

Inequality

~=, ^=, ne

Less than

<, lt

Less than or equality

<=, le

Greater than

>, gt

Greater than or equality

>=, ge

Conditional processing is written as:

if EXPR then ASSIGNMENT;

Multi-statement conditional processing

do blocks enable a single EXPR to apply to multiple statements.

if EXPR then do;
    ASSIGNMENT1;
    ASSIGNMENT2;
end;

Compound Logic

and and or operators chain conditions. (& and |, as well as several more obscure platform-dependent characters, are also options.) Parentheses group conditions as expected.

SAS supports a full if ... elif/else system.

if EXPR then ASSIGNMENT;
else if EXPR then do;
    ASSIGNMENT1;
    ASSIGNMENT2;
end;
else ASSIGNMENT;

Finally, SAS supports a case matching system.

select(VAR);
    when(VAL) ASSIGNMENT;
    when(VAL) do;
        ASSIGNMENT1;
        ASSIGNMENT2;
    end;
    otherwise ASSIGNMENT;
end;

Membership test

Membership tests can be written as VAR in VALUELIST, where VALUELIST is a list of space and/or comma delimited values surrounded by parentheses. The test can be negated using not in.

Range test

Range tests can be written as MIN < VAR < MAX or VAR between MIN and MAX.

Missing value test

Missing values are . for numeric variables and "" (empty string) for string variables. These can be tested literally, or using VAR is missing. The test can be negated using is not.

String matching test

String matching is written as VAR like PATTERN or VAR =* PATTERN. The rules for PATTERN are:

For case-insensitive matching, instead test upcase(VAR) and an all-uppercase PATTERN.

Assignment Operators

Precisely what you expect: +, -, *, /, and **.

Common Functions


CategoryRicottone