turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- Rounding down by 2 dp

Topic Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

01-29-2018 11:49 AM

Hi,

What function can be used to round down a number by 2 dp, for instance if I have the value of 0.99856 how can I round this down to 0.99?

Many Thanks

Adnan

Accepted Solutions

Solution

01-29-2018
12:04 PM

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Adnan_Razaq

01-29-2018 11:55 AM

That's not rounding, that's truncation, rounding to 2 decimal places would be 1.00.

Note, please use full words, ie dp=decimal place is my assumption. Not everyone here will know your terminology.

```
data want;
x=0.99856;
y=floor(x*100)/100;
y=round(y, 0.01);
put x= y=;
run;
```

Adnan_Razaq wrote:

Hi,

What function can be used to round down a number by 2 dp, for instance if I have the value of 0.99856 how can I round this down to 0.99?

Many Thanks

Adnan

All Replies

Solution

01-29-2018
12:04 PM

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Adnan_Razaq

01-29-2018 11:55 AM

That's not rounding, that's truncation, rounding to 2 decimal places would be 1.00.

Note, please use full words, ie dp=decimal place is my assumption. Not everyone here will know your terminology.

```
data want;
x=0.99856;
y=floor(x*100)/100;
y=round(y, 0.01);
put x= y=;
run;
```

Adnan_Razaq wrote:

Hi,

What function can be used to round down a number by 2 dp, for instance if I have the value of 0.99856 how can I round this down to 0.99?

Many Thanks

Adnan

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Reeza

a month ago

HI Reeza,

Thanks for this solution! Just a question about "y=round(y, 0.01)" as I'm not sure if it's necessary. When I run your code without it, it seems to work fine. Am I missing something? Thanks!

-Joey

Thanks for this solution! Just a question about "y=round(y, 0.01)" as I'm not sure if it's necessary. When I run your code without it, it seems to work fine. Am I missing something? Thanks!

-Joey

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to jt742

a month ago

It depends on what you want. Round will round the variable to the nearest second decimal place in this case. I think this is the same as using 8.2 format to display your data. However, 8.2 only controls the display, the value in the table would still be the actual value, so it depends on what you're trying to do overall.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Adnan_Razaq

01-29-2018 11:59 AM

Can you have negative numbers, such as:

-0.98776

If so, what result would you want to see?

One possible way to program this (depending on your answer):

x = int(100*x) / 100;