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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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


 

View solution in original post

4 REPLIES 4
Reeza
Super User

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


 

jt742
Calcite | Level 5
HI Reeza,

Thanks for this solution! Just a question about "y=round(y, 0.01)" as I'm not sure if it's necessary. When I run your code without it, it seems to work fine. Am I missing something? Thanks!

-Joey
Reeza
Super User

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.

Astounding
PROC Star

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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 13278 views
  • 1 like
  • 4 in conversation