Mathematical Operators
Var3 = Var1 + Var2;
Var3 = Var1 - Var2;
Var3 = Var1 * Var2;
Var3 = Var1 / Var2;
Let's start with something simple.
Below is the NUMBERS data set.
It contains 2 variables: VAL1 and VAL2.
Note: the yellow box below contains the code for the NUMBERS data set.
Copy and run the code to get the NUMBERS data set on SAS Studio.
To add, subtract, multiply and divide values in SAS, you can use the following mathematical operators:
Add & Subtract
Data Math1;
Set Numbers;
val3 = val1 + val2;
val4 = val1 - val2;
Run;
Multiplication & Division
Data Math2;
Set Numbers;
val3 = val1 * val2;
val4 = val1 / val2;
Run;
Exercise
Copy and run the ACCOUNTING data set from the yellow box below.
ACCOUNTING contains 4 variables:
EmployeeID: ID
Base: Base Salary
OTHours: Overtime Hours
Rate: Overtime Rate
Employee's salary is calculated as Base Salary + (Overtime Hours x Overtime Rate)
Write a SAS program to calculate the salary for each employee. Create any data set or variables if necessary.
You must create a new variable that contains the salary information based on the equation provided.
Data EmpSalary;
Set Accounting;
Salary = Base + OTHours*Rate;
Run;
Note: The data set we created is called EMPSALARY. You do not need to follow our data set naming convention. You can name your data set any way you want. Same for the variable SALARY.
Cookie | Duration | Description |
---|---|---|
cookielawinfo-checkbox-analytics | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics". |
cookielawinfo-checkbox-functional | 11 months | The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional". |
cookielawinfo-checkbox-necessary | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary". |
cookielawinfo-checkbox-others | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other. |
cookielawinfo-checkbox-performance | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance". |
viewed_cookie_policy | 11 months | The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data. |