 Return to Archive SAS Tip of the Month January 2007 Welcome to 2007! I hope the New Year was good to you. This month I will look at rounding numbers and four different functions that SAS gives to rounding. The four that will be looked at here are: floor(x) - returns the largest integer that is less than or equal to x ceil(x) - returns the smallest integer that is greater than or equal to x round(x) - returns the nearest integer value nearest to x int(x) - returns the integer value of x The following code and output demonstrates the output of certain values of x when the functions above are applied to the value x: ``` data x; infile cards; input x; fl=floor(x); cl=ceil(x); ro=round(x); in=int(x); label fl='floor(x)' cl='ceil(x)' ro='round(x)' in='int(x)'; cards; 1.6 1.5 1.4 1.0 0.0 -1.0 -1.4 -1.5 -1.6 ; run; title1 "x Rounded Using Four SAS Rounding Functions"; proc print data=x label; run; === Output === x Rounded Using Four SAS Rounding Functions Obs x floor(x) ceil(x) round(x) int(x) 1 1.6 1 2 2 1 2 1.5 1 2 2 1 3 1.4 1 2 1 1 4 1.0 1 1 1 1 5 0.0 0 0 0 0 6 -1.0 -1 -1 -1 -1 7 -1.4 -2 -1 -1 -1 8 -1.5 -2 -1 -2 -1 9 -1.6 -2 -1 -2 -1``` Have a very happy 2007. See you in February. ________________________________ Updated January 10, 2007