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

Hello,

 

I need to know if SAS EG has the capabilities of rounding up to the third decimal place if there is a fourth numeric value when doing the division?  I understand the round/ceil/floor functions but I'm not getting the expected results.

 

Data:

17/30 = .5666666666666667 = output = .567 (correct)

1/30 = .03333333333333 = output = .033 (incorrect) wanting output to be .034

 

I understand the ROUND function is working properly but I'm needing the third decimal to round up if there is a 4th value period.

 

This is currently what is coded:

ROUND(((INPUT(t1.'QUANTITY LIMIT AMOUNT'n, best10.))/(INPUT(t1.'QUANTITY LIMIT DAYS'n, best10.))),0.001
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Ignoring all of the INPUT stuff try:

(ceil(round( 1/30 ,0.0001)*1000))/1000

CEIL and FLOOR result in integer values, so you need to do the decimal positioning manually when using a non-standard "rounding" approach.

 

 

View solution in original post

5 REPLIES 5
ballardw
Super User

Ignoring all of the INPUT stuff try:

(ceil(round( 1/30 ,0.0001)*1000))/1000

CEIL and FLOOR result in integer values, so you need to do the decimal positioning manually when using a non-standard "rounding" approach.

 

 

shaymo
Calcite | Level 5

Thank you so much!!  It works beautifully!

ed_sas_member
Meteorite | Level 14

Hi @shaymo 

 

Welcome to the community!

Here is a suggestion to round up everytime:

 

%let decimal = 1000;

data have;
	var1_notrounded = (17/30)*&decimal.;
	var1 = ceil(var1_notrounded) / &decimal.;
	var2_notrounded = (1/30)*&decimal.;
	var2 = ceil(var2_notrounded) / &decimal.;
	var3_notrounded = INPUT(t1.'QUANTITY LIMIT AMOUNT'n, best10.)/INPUT(t1.'QUANTITY LIMIT DAYS'n, best10.)*&decimal.;
	var3 = ceil(var3_notrounded) / &decimal.;
run;

Best,

shaymo
Calcite | Level 5

Thank you for the response!  This could also work but I'm real new to SAS EG and honestly don't know how to code per your example.  Appreciate your help!

Tom
Super User Tom
Super User

You could round and if the value went down add 0.001.

data test;
  input x;
  y=round(x,0.001)+0.001*(round(x,0.001)<x);
cards;
.566667
.333333
;
proc print;
run;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 950 views
  • 0 likes
  • 4 in conversation