To find the floor of a number in a SAS data step, the easiest way is to use the SAS floor() function.
data data_with_floor;
set data;
floor = floor(num);
run;
When working with data, sometimes we have the need to round numbers down to their floor.
In SAS, we can round numbers down to their floor easily. The SAS floor() function returns the floor of a number.
Finding the Floor of a Number in SAS
We can find the floor of a number in a SAS data step very easily with the SAS floor() 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 down to the nearest integer, we just need to pass the variable “num” to the ceil() function.
data data_with_floor;
set data;
floor = floor(num);
run;
This results in the following SAS dataset:
num floor
1 84.31 84
2 19.23 19
3 5.6 5
4 -0.4 -1
5 -6.5 -7
6 -100.2 -101
Other SAS Rounding Methods to Round Numbers
Rounding down a number to the floor with the SAS floor() function is just one of the rounding functions you can use in your SAS code.
If you instead want to round a number up, you can use the SAS ceil() function.
data data_with_ceiling;
set data;
ceiling = ceil(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 down to the nearest integer with the SAS floor() function.