x
Need help studying for the new
SAS Certified Specialist Exam?
SAS Certified Specialist Exam?
Get access to:
- Two Full Certificate Prep Courses
- 300+ Practice Exercises
|
Lesson 5: Common SAS Operators
IMPORTANT! We have recently updated our training materials. Check out the latest free training here. In this lesson, we will explain the basic SAS operators (+-*/) and some simple calculation functions. 1. SAS Operators - Summation, Subtraction, Multiplication and Division
Example The dataset above contains the salaries for both Amy and John. We are going to add up the salary for each staff for the monthly pay cheque. Notice: Amy is missing the last week of work so that her salary in week 4 is missing.
Summation There are two methods to add up a number: Method 1: A = B + C (Not Recommended) Method 2: A = sum (of B, C) (Recommended) DATA SAL_4WEEK; Set SALARY; SALARY1 = WEEK1 + WEEK2 + WEEK3 + WEEK4; SALARY2 = SUM (OF WEEK1, WEEK2, WEEK3, WEEK4); RUN; As you can see, the two summation methods return the different results when there is a missing field (See Amy's Salary 1 and 2). Salary1, using summation method 1, returns a missing result since the Week-4 salary is missing. In contrast, Salary2 simply skips the missing salary and add up the 3 non-missing salaries from week1 to week3.
Method 2 is more commonly used as any missing value is being taken care of in the function. Subtraction, Multiplication and Division Subtraction, multiplication and division are quite straightforward: Example The code below computes the BMI for each patients:
DATA BMI2; Set BMI; BMI = WEIGHT / (HEIGHT*HEIGHT); RUN; DONE! You have learned the basic operators in SAS!
|
|