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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 1435 views
  • 0 likes
  • 4 in conversation