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

Hello Team ,

 

I have to avoid the division with zeros So, i have written below code for it .

it was not working with some variable and for those variables i am getting some big exponential number .

Code was :

If premium_cost ne 0 then premium_percentage=(premium_comm/premium_cost ) ;

here 

premium_cost is  zero .

premium_comm is 27.6

I am gettting premium_percentage=3.106E8.

 

I have some alternates divide function,<>, case function as well but gettting same permium_percentage.

 

Please kindly help me here.

 

Thanks & Regards,

Itharaju.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

If round(premium_cost, 1) ne 0 then do.....

 

 

Numerical precision, your number is likely 0.0000001 which is not equal to 0 so it still does the division. Use ROUND() to round the value for comparison.  


@Itharaju wrote:

Hello Team ,

 

I have to avoid the division with zeros So, i have written below code for it .

it was not working with some variable and for those variables i am getting some big exponential number .

Code was :

If premium_cost ne 0 then premium_percentage=(premium_comm/premium_cost ) ;

here 

premium_cost is  zero .

premium_comm is 27.6

I am gettting premium_percentage=3.106E8.

 

I have some alternates divide function,<>, case function as well but gettting same permium_percentage.

 

Please kindly help me here.

 

Thanks & Regards,

Itharaju.

 


 

View solution in original post

3 REPLIES 3
Reeza
Super User

If round(premium_cost, 1) ne 0 then do.....

 

 

Numerical precision, your number is likely 0.0000001 which is not equal to 0 so it still does the division. Use ROUND() to round the value for comparison.  


@Itharaju wrote:

Hello Team ,

 

I have to avoid the division with zeros So, i have written below code for it .

it was not working with some variable and for those variables i am getting some big exponential number .

Code was :

If premium_cost ne 0 then premium_percentage=(premium_comm/premium_cost ) ;

here 

premium_cost is  zero .

premium_comm is 27.6

I am gettting premium_percentage=3.106E8.

 

I have some alternates divide function,<>, case function as well but gettting same permium_percentage.

 

Please kindly help me here.

 

Thanks & Regards,

Itharaju.

 


 

Astounding
PROC Star

Assuming that @Reeza accurately identified the problem, you need to decide what to do when your variable is nearly zero.  If you want to avoid dividing for that case, you can use:

 

If round(premium_cost, 0.00000001) ne 0 then premium_percentage=(premium_comm/premium_cost ) ;

You may need to experiment with the number of zeros after the decimal point.

Ksharp
Super User
premium_percentage=(premium_comm/premium_cost ) ;
==>
premium_percentage=divide(premium_comm , premium_cost ) ;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 1296 views
  • 3 likes
  • 4 in conversation