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

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

Did you try adding 5?

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

View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User

Did you try adding 5?

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

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

PaigeMiller
Diamond | Level 26

@RZ123 

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

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)

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 4 replies
  • 1211 views
  • 4 likes
  • 3 in conversation