You can use the FLOOR function in SAS to return the largest integer less than or equal to some numeric value.
The following example shows how to use the FLOOR function in practice.
Note: The opposite of the FLOOR function in SAS is the CEIL function.
Example: How to Use FLOOR Function in SAS
Suppose we have the following dataset in SAS that contains information about the average items sold by various employees at some company:
/*create dataset*/
data my_data;
input employee $ avg_sales;
datalines;
Andy 12.3
Bob 14.5
Chad 8.44
Derrick 12.87
Eric 8.01
Frank 10
George 11.5
Henry 11.99
Isaac 7.64
;
run;
/*view dataset*/
proc print data=my_data;
We can use the FLOOR function to return the largest integer less than or equal to each numeric value in the avg_sales column:
/*create new dataset*/
data new_data;
set my_data;
floor_avg_sales = floor(avg_sales);
run;
/*view new dataset*/
proc print data=new_data;
Notice that the new column called floor_avg_sales contains the largest integer less than or equal to each numeric value in the avg_sales column.
For example:
- The value 12.30 becomes 12.
- The value 14.50 becomes 14.
- The value 8.44 becomes 8.
- The value 12.87 becomes 12.
And so on.
The Difference Between FLOOR vs INT Functions
The INT function in SAS returns the whole number portion of numeric values.
For positive values, the FLOOR and INT functions will return the exact same numbers.
However, the FLOOR and INT functions will return different values for negative numbers.
Consider the following dataset as an example:
/*create dataset*/ data my_data; input employee $ avg_sales; datalines; Andy 12.3 Bob 14.5 Chad 8.44 Derrick -12.87 Eric -8.01 /*create new dataset*/ data new_data; set my_data; floor_avg_sales = floor(avg_sales); int_avg_sales = int(avg_sales); run; /*view new dataset*/ proc print data=new_data;
For positive numeric values, the FLOOR and INT functions return the same results.
However, they don’t return the same results for negative numeric values.
The FLOOR function essentially rounds negative numbers down to the next integer while the INT function rounds negative numbers up to the next integer.
Additional Resources
The following tutorials explain how to perform other common tasks in SAS:
How to Round Numbers in SAS
How to Remove Commas from Strings in SAS
How to Display Values in Percent Format in SAS