I am asked to round 345.653 to the nearest integer values.
I used x=round(345.653, 1) and i got 346.000 is this the correct answer ? I was expecting 345 as my answer. How can i get 345 ?
INT() grabs the integer portion ignoring the decimal component entirely.
ROUND() rounds to the nearest interval - where you can specify what interval you want, with the default being 1.
Nearest interval varies because you can round to the nearest 1, 5, 10 or 15 in SAS which is often quite convenient.
In this case, your number is 345.653 which is closer to 346 rather than 345 so 346 is the correct value when rounding to the nearest integer.
You need to decide which one you want to use, but both work appropriately.
@CathyVI wrote:
I am asked to round 345.653 to the nearest integer values.
I used x=round(345.653, 1) and i got 346.000 is this the correct answer ? I was expecting 345 as my answer. How can i get 345 ?
What you wrote sounds like you'd rather prefer INT than a ROUND up/down. Can you confirm?
If yes, use
x=int(345.653)
In that case, all you need is
x=round(345.653) ;
INT doesn't work here. You need to use ROUND().
@CathyVI wrote:
I am asked to round 345.653 to the nearest integer values.
I used x=round(345.653, 1) and i got 346.000 is this the correct answer ? I was expecting 345 as my answer. How can i get 345 ?
It is the correct value for the typically used "round half up" method. Anything from 345.5 and up is rounded up to 346.
INT() grabs the integer portion ignoring the decimal component entirely.
ROUND() rounds to the nearest interval - where you can specify what interval you want, with the default being 1.
Nearest interval varies because you can round to the nearest 1, 5, 10 or 15 in SAS which is often quite convenient.
In this case, your number is 345.653 which is closer to 346 rather than 345 so 346 is the correct value when rounding to the nearest integer.
You need to decide which one you want to use, but both work appropriately.
@CathyVI wrote:
I am asked to round 345.653 to the nearest integer values.
I used x=round(345.653, 1) and i got 346.000 is this the correct answer ? I was expecting 345 as my answer. How can i get 345 ?
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.