# SAS Operators

In the SAS, operators are the symbols, which areused to perform calculations like addition, multiplication, subtraction, division, comparison, etc. These symbols are in-built part of SAS programming language, so we can combine these symbols in a single expression to get the desired output.

There are five types of operators in the SAS:

• Arithmetic Operators
• Logical Operators
• Comparison Operators
• Minimum/Maximum Operators
• Precedence Operator

## Arithmetic Operators:

Arithmetic operators are used to perform mathematical calculations like addition, multiplication, subtraction, division, etc. The following table describes arithmetic operators with their operations.

Operator Description Example
- Subtraction 24-4=10
* Multiplication 6*3=32
/ Division 46/23=2
** Exponentiation 2**3=8

Let's understand through an example, how we can use arithmetic operators in the SAS programming.

Execute the above code in SAS studio: Output: As we can see in the output, all values have been calculated according to the arithmetic operators.

## Logical Operators

Logical operators are used to evaluate the truth or false value of an expression.The result of logical operator is always Boolean value, i.e., 1 or 0. The following table describes logical operators with their operations.

Operator Description Example
& This symbol is calledthe AND Operator. If both data values evaluate true, then the result is 1 else it is 0. (5>2 & 2> 3) gives 0 or false.
| This symbol is calledthe OR Operator. If any one of the data values evaluates true, then the result is 1 else it is 0. (10>9 & 5> 3) gives 1 or true.
~ This symbol is called The NOT Operator. If the values evaluate false, then the result is 1 else, it is 0. NOT(8> 3) is 1 or true.

Let's understand through an example, how we can use logical operators in SAS programming.

Execute the above code in SAS studio: Output: As we can see in the output, all values are producing Boolean results according to the evaluation of logical operators.

## Comparison Operators

Comparison operators areused to compare the values on the basis of equality. The result of comparison operator is always Boolean value, i.e., 1(for true) or 0 (for false). The following table describes comparisonoperators with their operations.

Operator Description Example
= This symbol is called the EQUAL Operator. If both values are equal, then the result is 1 else it is 0. (8 =8) gives 1. (4=8) gives 0.
^= This symbol is called theNOT EQUAL Operator. If both values are unequal, then the result is 1 else it is 0. (3 ^= 5) gives 1. (5^= 5) gives 0.
< This symbol is called theLESS THAN Operator. (2 < 9) gives 1. (12 < 9) gives 0.
<= This symbol is called theLESS THAN or EQUAL TO Operator. (3<= 4) gives 1. (4 <= 4) gives 1. (7 <= 4) gives 0.
> This symbol is called theGREATER THAN Operator. (22 > 20) gives 1. (10 > 20) gives 0.
>= This symbol is called theGREATER THAN or EQUAL TO Operator. (10 >=5) gives 1. (5 >=5) gives 1. (3 >=5) gives 0.
IN If the value is equal to any of the value in a given list, then it returns 1 else returns 0. 9 in (5,7,9,8) gives 1. 2 in (5,7,9,8) gives 0.

Let's understand through an example, how we can use comparison operators in SAS programming.

Execute the above code in SAS studio: Output: As we can see in the output, all values are producing Boolean results according to the evaluation of comparison operators.

## Minimum/Maximum Operators

These operators are used to compare the values of the variable across the row to return the maximum or minimum value from the list of values in the row.The following table describes Minimum/Maximum Operators with their operations.

Operator Description Example
MIN This group of alphabets is called theMIN Operator. It returns the minimum value from the entire row. MIN(45.2,11.6,15.41) gives 11.6
MIN This group of alphabets is called theMAX Operator. It returns the maximum value from the entire row. MAX(46.3,11.6,15.41) gives 46.3

Execute the above code in SAS studio: Output: As we can see in the output, minimum and maximum operators have returned the minimum and maximum values from the list of values in both rows.

## Concatenation Operator

Concatenation Operator is used to concatenate two or more string values. The following table describes the Concatenation Operator with its operation.

Operator Description Example
|| This symbolis called theconcatenate Operator. It concatenates two or more string values. 'Hello'||' SAS gives Hello SAS

Execute the above code in SAS studio: Output: As we can see in the output, both string variables have been concatenated.

## Precedence Operator:

Precedence Operator is a group of operators which indicates the order of evaluationin the case when multiple operators present in a complex expression.The following table describes Precedence Operatorswith their operations.

Group Order Symbols
Group I Right to Left ** + - NOT MIN or MAX
Group II Left to Right * /
Group III Left to Right + -
Group IV Left to Right ||
Group V Left to Right <<= = >= >    