BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
duckduckgo
Fluorite | Level 6
round(3.1415, 1.2) = 2.6, it looks like it's right. but round(3.1415, 1.5) = 3, why?
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Is that a typo? round(3.1415, 1.2) = 3.6, not 2.6

 

As far as round(3.1415,1.5), 3 is the closest multiple of 1.5 to the value 3.1415

--
Paige Miller

View solution in original post

6 REPLIES 6
antonbcristina
SAS Super FREQ

Hi @duckduckgo, according to the documentation on the ROUND function, it rounds the first argument to the nearest multiple of the second argument. The nearest multiple of 1.2 is 3.6 (I believe this was a typo in your original message) and the nearest multiple of 1.5 is indeed 3.  

duckduckgo
Fluorite | Level 6
thank you
ദ്ദി˶˃ ᵕ ˂ )✧
PaigeMiller
Diamond | Level 26

Is that a typo? round(3.1415, 1.2) = 3.6, not 2.6

 

As far as round(3.1415,1.5), 3 is the closest multiple of 1.5 to the value 3.1415

--
Paige Miller
duckduckgo
Fluorite | Level 6
thank you, I get it.
ballardw
Super User

When you use the ROUND function SAS attempts to display the first argument as the nearest multiple of the second. The only possible multiples for any value rounded to 1.5 are 0, 1.5, 3, 4.5, 6, etc.

Round is not division, which seems to be what  you are interpreting this to be.

Consider this example:

data example;
x1 = round(3.1415,1.45);
x2 = round(3.1415,1.46);
x3 = round(3.1415,1.47);
x4 = round(3.1415,1.48);
x5 = round(3.1415,1.49);
x6 = round(3.1415,1.5);
x7 = round(3.1415,1.51);
x8 = round(3.1415,1.52);
run;

The nearest value to 3.1415 of a multiple of 1.45 is 2*1.45 or 2.9. of 1.46 is 2*1.46 or 2.92 ... 2*1.5=3

 

If you are playing around with Pi you may want to consider looking up the CONSTANT function to return better values of some constant values such as pi.

duckduckgo
Fluorite | Level 6
thank you so much, i get it.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 6 replies
  • 3341 views
  • 8 likes
  • 4 in conversation