BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
milts
Pyrite | Level 9

Hi Experts,

Would like to consult regarding the round function.

Given the value 123.456 for a, how come this turns out to be the value when I use the round function.

ROUND parameter

a = 123.456

Result
b = round(a,0.01)123.46 (ok)
b = round(a,0.02)123.46 (ok)
b = round(a,0.03)123.45 (?)
b = round(a,0.04)123.44 (?)
b = round(a,0.05)123.45 (?)
b = round(a,0.06)123.48 (?)
b = round(a,0.07)123.48 (?)
b = round(a,0.08)123.44 (?)
b = round(a,0.09)123.48 (?)

Is there a bug on the round function or is there something I am not aware on how it derives into these results. Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
RichardinOz
Quartz | Level 8

The second number in the SAS round function specifies the units that should be rounded to, so for example round(123.456, .03) says round the number to the nearest multiple of .03 .  There are 4115.2 multiples of .03 in the number 123.456; rounding this to the nearest integer gives 4115 multiples.  Multiplying back correctly gives the resultant 123.45, and so for the other values of rounding unit.

Initial value

Rounding Unit

Number of Multiples

Multiples Rounded

Multiplied back

123.456

0.01

12345.6

12346

123.46

123.456

0.02

6172.8

6173

123.46

123.456

0.03

4115.2

4115

123.45

123.456

0.04

3086.4

3086

123.44

123.456

0.05

2469.12

2469

123.45

123.456

0.06

2057.6

2058

123.48

123.456

0.07

1763.657143

1764

123.48

123.456

0.08

1543.2

1543

123.44

123.456

0.09

1371.733333

1372

123.48

View solution in original post

4 REPLIES 4
RichardinOz
Quartz | Level 8

The second number in the SAS round function specifies the units that should be rounded to, so for example round(123.456, .03) says round the number to the nearest multiple of .03 .  There are 4115.2 multiples of .03 in the number 123.456; rounding this to the nearest integer gives 4115 multiples.  Multiplying back correctly gives the resultant 123.45, and so for the other values of rounding unit.

Initial value

Rounding Unit

Number of Multiples

Multiples Rounded

Multiplied back

123.456

0.01

12345.6

12346

123.46

123.456

0.02

6172.8

6173

123.46

123.456

0.03

4115.2

4115

123.45

123.456

0.04

3086.4

3086

123.44

123.456

0.05

2469.12

2469

123.45

123.456

0.06

2057.6

2058

123.48

123.456

0.07

1763.657143

1764

123.48

123.456

0.08

1543.2

1543

123.44

123.456

0.09

1371.733333

1372

123.48

Haikuo
Onyx | Level 15

Wow, This is awesome! I did not know that. Learn some. Thanks a lot!

Haikuo

milts
Pyrite | Level 9

This is totally great explanation regarding the round function. I believe most are not also aware of this. Thank you very much! You have just expanded my knowledge! Smiley Happy

RichardinOz
Quartz | Level 8

I can envisage there might be a situation where round(x, .02) or round(x, .05) might be required but I cannot imagine why anyone would want round(x, .03) or round(x, .07).  However, it is there if needed.  You can also round to other fractions like quarters, round(x, .25) or eighths, round(x, .125) etc.

Rounding a whole number by say .07 can yield unexpected results: round(123, .07) = 122.99 ( ! ).

milts, thanks for your comment.  Can you mark this answered?

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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