Most people use the round function to round to the nearest decimal. There are other great ways to use the round function. You can use it to round to something other than the nearest decimal, such as to the nearest dollar value or to round times. The following code snipets provide examples of how you can expand your use of the round function.
Example showing how to round to the nearest decimal.
DATA _null_;
cost = 4.99;
units = 3;
ucost = Round(cost/units,.01);
PUT cost units ucost ;
RUN;
Example showing how to round a single value to the nearest quarter, the nearest nickel, and the nearest $5.
DATA _null_;
x = 234.2357222;
x2 = Round(x, .25); * the nearest quarter;
x3 = Round(x, .05); * the nearest nickel;
x4 = Round(x, 5); * the nearest 5 dollars;
Put x x2 x3 x4;
RUN;
Example showing how to round times.
First a SAS datetime value is created using the DHMS function.
Then the ROUND function is used with the HMS function to round to the nearest 15 minutes, 7 1/2 minutes and 15 seconds.
DATA _null_;
dt = dhms('12mar2003'D,14,23,10); * create a datetime - 2:23pm;
dt2 = Round(dt,hms(0,15,00)); * round it to nearest 15 minutes;
dt3 = Round(dt,hms(0,7,30)); * round it to nearest 7 1/2 minutes;
dt4 = Round(dt,hms(0,0,15)); * to the nearest 15 seconds;
Put (dt dt2 dt3 dt4) (DATETIME. ' ');
RUN;
Example showing how to round times using datetime constants.
DATA _null_;
dt = '12mar2003:14:23:10'DT; * create a datetime - 2:23pm;
dt2 = Round(dt,'0:15:00'T); * round it to nearest 15 minutes;
dt3 = Round(dt,'0:7:30'T); * round it to nearest 7 1/2 minutes;
dt4 = Round(dt,'0:00:15'T); * to the nearest 15 seconds;
Put (dt dt2 dt3 dt4) (DATETIME. ' ');
RUN;

About the Author
Richard Wright began writing SAS code over 25 years ago keying code and data on punch cards as a student at University of Oregon. Since then he has worked at various agencies for the state of Texas. He is certified in Base and Advanced SAS.