- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I have a set of values which have a large number of digits to the right of the decimal. I need a way to round to the nearest tenth while NOT rounding up to the next integer if the decimal value is >= .95 . For instance:
Raw Value -- Preferred Rounded Value
2.9546732 -- 2.9
4.5423 -- 4.5
4.5734 -- 4.6
0.983764 -- 0.9
9.89473 -- 9.9
9.99999964 -- 9.9
Any idea on how to perform this?
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
This is most unusual. But can be done:
data _null_;
do x = 2.9546732, 4.5423, 4.5734, 0.983764, 9.89473, 9.99999964;
y = int(x) + ifn(x-int(x) >= 0.9, 0.9, round(x-int(x),0.1));
put x= y=;
end;
run;
x=2.9546732 y=2.9 x=4.5423 y=4.5 x=4.5734 y=4.6 x=0.983764 y=0.9 x=9.89473 y=9.9 x=9.99999964 y=9.9
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@RandoDando wrote:
I have a set of values which have a large number of digits to the right of the decimal. I need a way to round to the nearest tenth while NOT rounding up to the next integer if the decimal value is >= .95 . For instance:
Raw Value -- Preferred Rounded Value
2.9546732 -- 2.9
4.5423 -- 4.5
4.5734 -- 4.6
0.983764 -- 0.9
9.89473 -- 9.9
9.99999964 -- 9.9
Any idea on how to perform this?
Do you have a similar aversion to rounding down to an integer such as when the value is 10.04 where the nearest tenth would be 10.0?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
This is most unusual. But can be done:
data _null_;
do x = 2.9546732, 4.5423, 4.5734, 0.983764, 9.89473, 9.99999964;
y = int(x) + ifn(x-int(x) >= 0.9, 0.9, round(x-int(x),0.1));
put x= y=;
end;
run;
x=2.9546732 y=2.9 x=4.5423 y=4.5 x=4.5734 y=4.6 x=0.983764 y=0.9 x=9.89473 y=9.9 x=9.99999964 y=9.9
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
num = int(num*10) / 10;