Sentry Page Protection
SAS Functions [3-14]
MEAN, MIN and MAX Function
You can probably tell what these functions do in SAS!
The MEAN, MIN and MAX functions allow you to compute the mean, minimum and maximum values from a set of variables, respectively.
Example
The NUMBERS data set above, again, contains 3 variables.
[Reminder: To see the NUMBERS data set on SAS Studio, run the code in the yellow box above]
Now, let's do some statistics computation.
Data Math;
Set Numbers;
m1 = mean(val0, val1, val2);
m2 = min(val0, val1, val2);
m3 = max(val0, val1, val2);
Run;
The variables M1, M2 and M3 are created.
They contain the mean, minimum and maximum values from VAL1, VAL2 and VAL3, respectively.
(Try it!)
Note: missing values will not affect the results.
The MEAN, MIN and MAX functions work despite the present of the missing values.
Exercise
Copy and run the EXAM data set from the yellow box below.
Copy and run the EXAM data set from the yellow box below.
EXAM contains 4 variables:
- ID: Student ID
- TEST1: First test result
- TEST2: Second test result
- FINAL: Final exam result
The final score is calculated as:
- 50% of (the highest of the first and second test) +
- 50% of the final exam result
Write a SAS program to calculate the final score for each student. Create any data set or variables if necessary.
Need some help?
HINT:
The formula for the final score is ( 0.5 x (highest of 1st and 2nd test) + 0.5 x final exam)
SOLUTION:
Data Exam2;
Set Exam;
Final_Score = 0.5 * max(test1, test2) + 0.5 * final;
Run;
Fill out my online form.