Arithmetic Operator
In SAS, there are five arithmetic operators. Below is the chart detailing each of the five operators:
Let's look at an example.
Data Test;
a = 3**2;
Run;
In this example, the value a is equal to 3 raised to the power of 2, which is 9.
Automatic Conversion
Sometimes, for whatever reason, you may choose to store a numeric value in a character variable.
When performing mathematical operations on such character variables, SAS will automatically convert the character values to numeric values.
Let's look at an example.
Data Retail;
cost = '20000';
total = .10 * cost;
run;
In this example, the COST variable contains a character value '20000'.
When multiplying the character value by 0.1, SAS will automatically convert the character value to a numeric value.
The total will be calculated as 2000.
✍️ Exam Tips
When performing a mathematical operation on a character variable, SAS will automatically convert the character values to numeric values before the operation.
? Sample Exam Question(s):
Question 1
Question 2
Question 1:
The answer is (b).
The variable Z contains 3 raised to the power 2. The answer is 9.
----
Question 2:
The answer is (a).
SAS automatically converts the character value '20000' to a numeric value (20000) before multiplying the value by 0.1. The result is 2000.
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. |