## Introduction to SAS Operators

Statistical Analysis System refers to a suite of software created by SAS Institute and has the ability to provide multivariate advanced analytics with data management and predictive capabilities. SAS as the software is used to retrieve, alter, manage data from a variety of sources and perform data analysis on the same. here we will discuss the SAS Operators.

SAS is a fourth generation programming Language extensively used in Statistical and mathematical analysis of data for providing an enterprise-level solution to complex business needs.

SAS was initially developed in 1966 to cater to the life sciences industry with primary use being in predictive analysis using variance and regression legacy data, SAS further developed its ability with the incorporation of JMP to combine with the Graphical User interface option provided in early MAC, with the continuous development philosophy and advancement in computational ability of scientific systems and the increasing load of omnipresent data SAS introduced data mining features in 2005.

Further development in the suite provided various features like excel import, experimental designing,

As of now, SAS is extensively used in providing Customer intelligence solutions, SAS also finds huge applications in Banking industries with the ability to identify fraudulent transactions, SAS products are also used in government, retail, telecommunications and aerospace and for marketing optimization or high-performance computing.

### The code structure of SAS Programming

The SAS program is built on the two building blocks:-

**DATA STEP:**It is used in dataset creation and variable assignment**PROC STEP:**It is used to process the data

### What are the Operators in SAS?

The SAS operators are symbols used in programming for arithmetic, logical or comparison operations.

**For e.g.**

- Y = X
**+**Z - Y
**>**5 - P in (1,2,3,4,5)

### Types of Operator in SAS

There are two major categories of operators in the SAS programming language which include Prefix Operators and Infix operators. The segregation between the two is based on the modus operandi of the operators.

**Prefix Operators**: It is a general expression used in defining the operators which are applied on the operands (are constants or variables that can be numeric or character) which follow the expression, the activity associated with the operators is applied immediately on the variable, expression, constants. Let us now try to understand examples of Prefix Operators- -y
- -cos(x)
- +(x*y)

It is also to be mentioned that the word NOT and its equivalent symbols are also considered as prefix operators.

**Infix Operators**: They are referred to those operators acting upon both the sides of the operators, these operators have generally involved in arithmetic as well as the logical operations in SAS programming. Subcategories of Infix operators are as follows- Arithmetic Operators
- Logical Operators
- Comparison Operators
- Concatenation Operators
- Maximum
- Minimum

### The Plus/Minus Anomaly

The questions arise in terms of a definition of plus and minus signs in SAS programming. Here one needs to understand the contextual inference of the Symbol, the easiest way to understand the scenario is when used in arithmetic calculations the plus/minus signs are considered as infix operators, Similarly, when used in the definition the symbols are categorized in Prefix operators.

### In-depth analysis of Infix Operators

Different Infix operators used as follows:

**Arithmetic operators:**Referred to the operators used in carrying out the arithmetic computations in SAS, the list of operators can be found below with the result

Operator |
Description |
Syntax |
Result (x=8 and y=2) |

+ | Addition | x+y | 10 |

– | Subtraction | x-y | 6 |

/ | Division | x/y | 4 |

* | Multiplication | x*y | 16 |

** | Exponentiation | x**y | 64 |

**Logical Operators**: Referred to those operators which are used in determining the truth value of an expression

Operator |
Description |
Syntax |
Result (x=8 and y=2) |

& | AND | E1 & E2 | (x>2 & y > 3) gives 0 |

| | OR | E1 | E2 | (x>2 & y > 3) is 1 |

~ | NOT | E1 ~ E2 | NOT(x > 3) is 0 |

**AND Operator:**The expression returns 1 if both the quantities linked by the AND operation are true**OR Operator:**The expression returns 1 if either of the quantities linked by the OR operation is true.**NOT Operator:**The NOT operator is a Logical operator it transposes the value of its operand to the logical opposite

**Comparison Operators**: They are referred to operators used to set up a comparison operation, or calculation with two variables, constants, or expressions. If the comparison is true, the result is 1. If the comparison is false, the result is 0.

Operator |
Description |
Syntax |
Result (x=8 and y=2) |

= | equal to | E1=E2 | (x=y) gives 0 |

~= | not equal to | E1~=E2 | (x~=y) gives 1 |

> | greater than | E1>E2 | (x>y) gives 1 |

< | less than | E1<E2 | (x<y) gives 0 |

>= | greater than or equal to | E1>=E2 | (x>=y) gives 1 |

<= | less than or equal to | E1<=E2 | (x<=y) gives 0 |

IN operator in SAS is used in the comparison of expression in the left to a list of Expression on the right for e.g.

x IN ** (**1,2,3,4,8,9,10

**will give 1 for the above example**

__)__It is to be noted that the expression on the Value end must be constant.

Character operations can be performed in SAS, Character operands are compared character by character from left to right. Two character values of unequal length are compared with the assumptions that blanks are attached to the end of the shorter string before the comparison is made.

**MIN/MAX operators:**The MIN/MAX operators in SAS are used to find the minimum and maximum value of two quantities

Operator |
Description |
Syntax |
Result (x=8 and y=2) |

<> | MAX | E1<>E2 | x<>y gives 8 |

>< | MIN | E1><E2 | x><y gives 2 |

**Concatenation Operator:**The Concatenation operator in SAS is used to integrate two strings.

Operator |
Description |
Syntax |
Result (x=Good and y=Bye) |

|| | Concatenation | E1||E2 | x||y gives GoodBye |

** **The length of the resulting string is equal to the sum of the length of the strings involved in the Concatenation operations,

### Order of Evaluation

The order of evaluation in a compound statement is dependent on the expression type:-

- Right to left -> the prefix operators, as well as the Exponential and MIN/MAX operators, uses the Right to left order of evaluation. Let us understand this with an example

Let us consider a SAS operation x=4**5**6 this will be evaluated as x= (4**(5**6))

- Left to right -> the operators such as addition, subtractions, multiplication, and division with comparison and logical AND, logical OR are evaluated as from left to right.

SAS also provides several other operators that are used only with certain SAS statements. The WHERE statement uses a special group of SAS operators, valid only when used with WHERE expressions.

### Recommended Articles

This has been a guide to SAS Operators. Here we have discussed different types of SAS Operators with examples and Order of Evaluation. You may also look at the following article to learn more –

- List of MySQL Operators
- C Operators with Syntax and Examples
- SASS Interview Questions
- Multivariate Regression

9 Online Courses | 10 Hands-on Projects | 123+ Hours | Verifiable Certificate of Completion

4.5

View Course

Related Courses