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

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 ?

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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 ?


 

View solution in original post

7 REPLIES 7
novinosrin
Tourmaline | Level 20

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)
CathyVI
Pyrite | Level 9
my goal is to change 345.653 to 346
novinosrin
Tourmaline | Level 20

In that case, all you need is

 

x=round(345.653)  ;
CathyVI
Pyrite | Level 9
the x=int(345.653) worked. I was able to get 346 but i have to create another variable
for example v1= int(345.653) = 346 but when i did
v1= int(v1), i got the 345.000.
Thank you
PaigeMiller
Diamond | Level 26

INT doesn't work here. You need to use ROUND(). 

--
Paige Miller
Kurt_Bremser
Super User

@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.

Reeza
Super User

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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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
  • 7 replies
  • 1598 views
  • 0 likes
  • 5 in conversation