• 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
  • VBA
  • About
You are here: Home / SAS / SAS ceil – Round Up to Ceiling of Number in a SAS Data Step

SAS ceil – Round Up to Ceiling of Number in a SAS Data Step

January 18, 2022 Leave a Comment

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.

Other Articles You'll Also Like:

  • 1.  SAS calculated – Use Columns Created from Select in PROC SQL
  • 2.  SAS round – Rounding Numbers in a SAS Data Step
  • 3.  SAS Remove Formats from Dataset with PROC DATASETS
  • 4.  SAS if then else – Write Conditional Expressions for Multiple Conditions
  • 5.  SAS select when – Evaluating Character Values for Conditional Processing
  • 6.  SAS Lowercase – Make String Lowercase with SAS lowcase function
  • 7.  Do Loop in SAS Macro Language
  • 8.  Round Number to 2 Decimal Places in SAS
  • 9.  Get Substring from Right in SAS
  • 10.  SAS Remove Labels from Dataset with PROC DATASETS

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

The Programming Expert is a compilation of hundreds of code snippets to help you find solutions to your problems in Python, JavaScript, PHP, HTML, SAS, and more.

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 © 2022 · The Programming Expert · About · Privacy Policy