Fluorite | Level 6

## Trying round up to 10/20/30/40 /50 etc

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
Super User

## Re: Trying round up to 10/20/30/40 /50 etc

``round_up = round( have + (10/2) , 10 );``
4 REPLIES 4
Super User

## Re: Trying round up to 10/20/30/40 /50 etc

``round_up = round( have + (10/2) , 10 );``
Fluorite | Level 6

## Re: Trying round up to 10/20/30/40 /50 etc

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!!

Diamond | Level 26

## Re: Trying round up to 10/20/30/40 /50 etc

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
Fluorite | Level 6

## Re: Trying round up to 10/20/30/40 /50 etc

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)

Discussion stats
• 4 replies
• 1573 views
• 4 likes
• 3 in conversation