Chapter Contents |
Previous |
Next |
SAS Language Reference: Dictionary |
The following table groups SAS operators according to their priority of evaluation (first column). In compound expressions, SAS evaluates the part of the expression that contains operators from Group I first; it evaluates Group II expressions next, and so on down to Group VII. Parentheses are often used in compound expressions to group operands; expressions within parentheses are evaluated before those outside. In addition, if a compound expression contains more than one operator from the same group, certain rules govern which part of the expression SAS evaluates first. These rules are listed in the table in the column named Order of Evaluation.
The other columns in the table are described here.
Priority | Order of Evaluation | Symbols | MnemonicEquivalent | Definition | Example |
---|---|---|---|---|---|
Group I | right to left | ** (table note 1) | exponentiation |
y=a**2; |
|
+ (table note 2) | positive prefix |
y=+(a+b); |
|||
- | negative prefix |
z=-(a+b); |
|||
ˆ¬ ~ (table note 3) | NOT | logical not |
if not z then put x; |
||
>< | MIN | minimum |
x=(a><b);(table note 4) |
||
<> | MAX | maximum |
x=(a<>b); |
||
Group II | left to right | * | multiplication |
c=a*b; |
|
/ | division |
f=g/h; |
|||
Group III | left to right | + | addition |
c=a+b; |
|
- | subtraction |
f=g-h; |
|||
Group IV | left to right | || !! ¦¦ (table note 5) | concatenate character values |
name= 'J'||'SMITH'; |
|
Group V (table note 6) | left to right (table note 7) | < | LT | less than |
if x<y then c=5; |
<= | LE | less than or equal to |
if x le y then a=0; |
||
= | EQ | equal to |
if y eq (x+a) then output; |
||
¬= | NE | not equal to |
if x ne z then output; |
||
>= | GE | greater than or equal to |
if y>=a then output; |
||
> | GT | greater than |
if z>a then output; |
||
IN | equal to one of a list |
if state in ('NY','NJ','PA') then region='NE'; |
|||
Group VI | left to right | & | AND | logical and |
if a=b & c=d then x=1; |
Group VII | left to right | | ! ¦ (table note 8) | OR | logical or |
if y=2 or x=3 then a=d; |
Because Group I operators are evaluated from right to left, the expression x=2**3**4 is evaluated as x=(2**(3**4)).
The plus (+) and minus (- ) signs can be either prefix or arithmetic operators. A plus or a minus sign is a prefix operator only when it appears at the beginning of an expression or when it is immediately preceded by a left parenthesis or another operator.
Depending on the characters that are available on your keyboard, the symbol can be the not sign (¬), tilde (~), or caret (^). The SAS system option CHARCODE allows various other substitutions for unavailable special characters.
In this example of the MIN operator, the SAS System evaluates -- 3>< -- 3 as -- (3>< -- 3), which is equal to -- ( -- 3), which equals +3. This is because Group I operators are evaluated from right to left.
Depending on the characters that are available on your keyboard, the symbol you use as the concatenation operator can be a single vertical bar (|), broken vertical bar (¦), or exclamation mark (!).
Group V operators are comparison operators. The result of a comparison operation is 1 if the comparison is true and 0 if it is false. Missing values are the lowest in any comparison operation.
The symbols =< (less than or equal to) and => (greater than or equal to) are also allowed for compatibility with previous versions of the SAS System.
When making character comparisons, you can use a colon (:) after any of the comparison operators to compare only the first character(s) of the value. The SAS System truncates the longer value to the length of the shorter value during the comparison. For example, if name=:'P' compares the value of the first character of NAME to the letter P. See "Character Comparisons" in Chapter 4 for details.
An exception to this rule occurs when two comparison operators surround a quantity. For example, the expression x<y<z is evaluated as (x<y) and (y<z).
Depending on the characters that are
available on your keyboard, the symbol you use for the logical or can be a
single vertical bar (|), broken vertical bar (¦), or exclamation mark
(!). You can also use the mnemonic equivalent OR.
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.