SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
abcda
Calcite | Level 5

I'm trying to perform a roundup function to mimic the function in Excel where I want to round up to the nearest decimal.

For example I would like to round -0.2011 to -.202

 

I've tried round, ceil, and floor but I can't seem to get it to round at the decimal level, only the integer level.

 

Any help would be greatly appreciated.

 

Thanks! 

2 REPLIES 2
PaigeMiller
Diamond | Level 26
newvalue=round(value+0.0005,0.001);

or

 

newvalue=ceil(1000*value)/1000;

 

 

--
Paige Miller
Astounding
PROC Star

If you are familiar with CEIL and FLOOR, you can probably do this yourself.

 

First, multiply by 1000.  Then apply CEIL or FLOOR (might depend on whether the number is positive or negative).  Then divide by 1000.

 

Be careful when you say rounding up or rounding down.  To the mathematician, -0.2011 to -0.202 is rounding down.

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 10838 views
  • 4 likes
  • 3 in conversation