Example 3: Rounding and truncating
Example 3 shows the use of the Round function. In this example we want to convert pounds to kilograms and inches to centimeters. Further, we want to round kilograms to the nearest whole number and round centimeters to the nearest tenth.
Data HTWT;
Input Weight Height;
KWeight = Weight/2.2;
CHeight = Height*2.54;
KWeight2 = Round(Weight/2.2, 1); * Rounded values;
CHeight2 = Round(Height*2.54, .1);
KWeight3 = Int(Weight/2.2); * Truncated to integer;
CHeight3 = Int(Height*2.54);
Datalines;
180 70
125 63
100 61
Proc Print data=HTWT noobs;
Run;
Which produces:
Weight Height KWeight CHeight KWeight2 CHeight2 KWeight3 CHeight3

180 70 81.8182 177.80 82 177.8 81 177
125 63 56.8182 160.02 57 160.0 56 160
100 61 45.4545 154.94 45 154.9 45 154
The syntax of the round function is:

 ROUND function (data step expressions) ROUND (argument-1, [argument-2]) The first argument is the numerical value to be rounded. The second argument is the round-off units.

Rounding rounds up or down, depending upon the fractional portion.
Truncating drops off the fractional portion and keeps only the integer portion.