How to Round Numbers in SAS?

While working with numeric data, you may need to round them. There are a few numerical functions in SAS which can help you to round numeric values. In this article, you will learn how to round numbers in SAS.

[Recomended Reading: How to truncate Decimals in SAS?]

To round numbers, you can use the ROUND function to round numeric values in SAS.


ROUND(argument <, rounding-unit>)

An argument is a number that is to be rounded. The rounding unit is an optional argument and is a positive number that specifies the rounding unit.

The ROUND function rounds the numbers to the nearest multiple of the rounding factor.

Data Numbers2;
input numbers;
data ex1;
set numbers2;
Randno1 = round(numbers,1);
Randno2 = round(numbers,2);
round numbers sas

How to Round to Nearest Whole numbers

To round to the nearest whole number, set the rounding unit to the multiple.

The following example shows how we can round up 1326 to the nearest multiple of 500.

Randno1 = round(1326,500);

The following steps are involved in the rounding process

  1. Work out how many times 500 goes into 1326, i.e. 1326 / 500 = 2.652
  2. Round this value up to the nearest integer, i.e. CEIL(2.652) = 3
  3. Multiply this value by the rounding unit, i.e. 3 * 500 = 1500

How to Round Decimals in SAS?

While rounding decimals, SAS finds an exact multiple of the rounding unit closest to the value to be rounded.

To truncate decimals in SAS without rounding, see our guide on How to truncate Decimals in SAS?

For example, 12.342 rounded to the nearest tenth equals 1 decimal place equals 12.3

Randno1 = round(12.342,0.1);

What if you want to round it to 2 decimal places?

Simply, you need to set the rounding factor to 0.01. 

Randno1 = round(12.342,0.01);

Round UP or Down in SAS – CEIL and FLOOR Function

The floor() Function in SAS takes up the column name as an argument and rounds down the column.

The Ceil() Function in SAS rounds up the number.

The CEIL and FLOOR functions round up or down, but they are limited to the nearest integer.

For example, it is impossible to round up to the nearest multiple of 10.

floor(1.95); /*Output 1 */ <br>ceil(1.95); /*Output 2*/

INT Function

The INT function in SAS returns only the integer portion of the argument.

data ex1;
var2= -1.94;
Round Numbers in SAS

We hoped this article helped you to round numbers in SAS

You may also want to see our article on How to check if a string is numeric in SAS? and Convert all character variables to numeric automatically.

Every week we'll send you SAS tips and in-depth tutorials


Subhro Kar is an Analyst with over five years of experience. As a programmer specializing in SAS (Statistical Analysis System), Subhro also offers tutorials and guides on how to approach the coding language. His website, 9to5sas, offers students and new programmers useful easy-to-grasp resources to help them understand the fundamentals of SAS. Through this website, he shares his passion for programming while giving back to up-and-coming programmers in the field. Subhro’s mission is to offer quality tips, tricks, and lessons that give SAS beginners the skills they need to succeed.