To find the ceiling of a number and round up in a SAS data step, the easiest way is to use the SAS **ceil()** function.

```
data data_with_ceiling;
set data;
ceiling = ceil(num);
run;
```

When working with data, sometimes we have the need to round numbers up to their ceiling.

In SAS, we can round numbers up to their ceiling easily. The SAS **ceil()** function returns the ceiling of a number.

## Finding the Ceiling of a Number in SAS

We can find the ceiling of a number in a SAS data step very easily with the SAS **ceil()** function.

Let’s say we have the following code which creates a SAS dataset with some numbers.

```
data data;
input num;
datalines;
84.31
19.23
5.6
-0.4
-6.5
-100.2
;
run;
```

To round up to the nearest integer, we just need to pass the variable “num” to the **ceil()** function.

```
data data_with_ceiling;
set data;
ceiling = ceil(num);
run;
```

This results in the following SAS dataset:

```
num ceiling
1 84.31 85
2 19.23 20
3 5.6 6
4 -0.4 0
5 -6.5 -6
6 -100.2 -100
```

## Other SAS Rounding Methods to Round Numbers

Rounding up a number to the ceiling with the SAS **ceil()** function is just one of the rounding functions you can use in your SAS code.

If you instead want to round a number down, you can use the SAS floor() function.

```
data data_with_floor;
set data;
floor = floor(num);
run;
```

If you want to round a number to the nearest integer, decimal, hundred, etc., you can use the SAS round() function.

```
data data_with_rounds;
set data;
round_to_ten = round(num, 10); /* rounds to nearest ten */
round_to_integer = round(num); /* rounds to nearest integer */
round_to_tenth = round(num, 0.1); /* rounds to nearest tenth */
run;
```

Hopefully this article has been useful for you to understand how you can round numbers up to the nearest integer with the SAS **ceil()** function.

## Leave a Reply