Using Numeric Functions..!!!

                                There are lot mathematical function that can be done through SAS. Starting from rounding numbers, computing dates from month-day-year values, summing and averaging the values of SAS variables, and hundreds of other tasks can be done in SAS. In this post we can see some of the numeric function by doing in SAS.

#Problem:

                               We want to compute the body mass index (BMI) from the health data set. Also we want to create four other variables based on BMI: 1) BMIRound is the BMI rounded to the nearest integer, 2)BMITenth is the BMI rounded to the nearest tenth, 3) BMIGroup is the BMI rounded to the nearest 5, and 4) BMITrunc is the BMI with a fractional amount truncated.

#Data set:

data A15028.A28_health;
   input Subj : $3.
         Height
         Weight;
datalines;
001 68 155
003 74 250
004 63 110
005 60 95
;


#Solution:


data A15028.A28_health1;
set A15028.A28_health;
BMI = (Weight/2.2) / (Height*.0254)**2;
BMIRound = round(BMI);
BMIRound_tenth = round(BMI,.1);
BMIGroup = round(BMI,5);
BMITrunc = int(BMI);
run;
Proc print data=A15028.A28_health1;
run;

#Output:



# Explanation and learning:

                                   As seen in the previous posts, first we are subsetting the data set from health to health1. Then we use the formula for BMI which is defined as the weight in kilograms divided by the height (in meters) squared. Then we use the round function with (.1) which denotes the nearest tenth and vice versa.


No comments:

Post a Comment