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

Showing results for

- Home
- /
- Programming
- /
- Programming
- /
- Trying round up to 10/20/30/40 /50 etc

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

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 04-08-2022 09:46 AM
(1572 views)

I am trying to round "UP" my numbers in a dynamic list to the nearest 10

so for example if the number of the list is 41, I need the function to return 50 as that value

I have tried this

data want;

set dataset;

round_multiple = round(var, 10);

round_ceil = ceil(var);

run;

the round multiple only rounds up if 5 or greater and rounds down 4 and lower

the ceil does not allow integer increases so it doesn't seem to work.

any thoughts on how to get this to work is much appreciated.

thanks!

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

4 REPLIES 4

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Did you try adding 5?

`round_up = round( have + (10/2) , 10 );`

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Brilliant! I did not, only change i had to make was doing 8/2 instead of 10, b/c the 10 brought (in my example 40 to the value of 50) but the 8 worked for say 41-44!

Thank you!!

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

I would not recommend this solution of using 8/2 = 4 to do the rounding, as I think it produces incorrect results (unless your data will only be integers). In the case where your data is not integers, the value 40.5 will round to 40, but that's not (if I am understanding you properly) rounding up.

On the other hand, this forces 40 to round to 40, and 40.5 to round to 50, and this makes more sense in general anyway.

```
if (have/10)=floor(have/10) then round_up=have; /* If have is an exact multiple of 10 */
else round_up = round( have + (10/2) , 10 );
```

--

Paige Miller

Paige Miller

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Yes thank you, This is probably more than you would like to know but in my example they are only whole numbers, basically it's part of a bigger formula that selects the TOP 10% of a dynamic file Month over Month the count is created Per line and the request was 10% of the total, however, if there are 41 (as my example) they want to base the top 10 on 50 rather than 40 (since 4.1 is the 10% of 41, however we can not give .1% of an account to QA)

That being said, I am looking into using what you're saying as I may in the future come up with a situation where they are not whole numbers and if it's constructed better for multi-purpose it makes sense to use yours even though the one above worked. (plus im lazy and like to steal things I did in the past for any future use)

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!

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.