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
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
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
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.
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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.