• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • Ruby
  • About
You are here: Home / SAS / SAS floor – Round Down to Floor of Number in a SAS Data Step

SAS floor – Round Down to Floor of Number in a SAS Data Step

January 18, 2022 Leave a Comment

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.

Other Articles You'll Also Like:

  • 1.  SAS yymmdd10. Date Format
  • 2.  SAS mean() Function – Find Average Across Columns in Data Step
  • 3.  Identifying Duplicates in SAS with PROC SORT dupout Option
  • 4.  SAS calculated – Use Columns Created from Select in PROC SQL
  • 5.  nodup vs nodupkey PROC SORT Options in SAS
  • 6.  SAS Dollar Format – Formatting Numbers as Dollars in SAS Dataset
  • 7.  SAS rename Statement – How to Rename Variables in a Data Step
  • 8.  countw SAS – Count Number of Words in a String
  • 9.  Using SAS to Sum by Group with PROC MEANS
  • 10.  catx SAS – Concatenate String Variables with Delimiter in SAS Data Step

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2023 · The Programming Expert · About · Privacy Policy