BookmarkSubscribeRSS Feed
alepage
Barite | Level 11

How to solve that issue?

 

NOTE: Division by zero detected at line 453 column 55.
province=AB policyNumber=************* riskNumber=2 driverType=Principal accountingYearMonth=202505 companyCode=3 branchNumber=15
12 The SAS System 09:40 Monday, August 11, 2025

writtenUnit_hyfi_sas=-0.92 writtenPremium_hyfi_sas=0 branch=15 - Calgary riskType=Automobile system=halcion company=Intact
acquisition= distribution=Broker writtenUnit_harmony=0 writtenPremium_harmony=0 writtenUnit_BI_harmony=0 journalEntry=1 flag=0
wu_diff_amt=0.92 wp_diff_pct=. _ERROR_=1 _N_=251

 

 

Data HyFi_sas_vs_harmony__byRisk ;
set HyFi_sas_vs_harmony__byRisk ;


if not missing(writtenUnit_harmony) then writtenUnit_harmony=round(writtenUnit_harmony, 0.0001);
if not missing(writtenUnit_HyFi_sas) then writtenUnit_HyFi_sas=round(writtenUnit_HyFi_sas, 0.0001);
if not missing(writtenUnit_harmony) and not missing(writtenUnit_HyFi_sas) then wu_diff_amt = Round(writtenUnit_harmony - writtenUnit_HyFi_sas, 0.001);

/*

What's the logic here, please explain ?

	If Missing(wu_diff_amt) Then wu_diff_amt = writtenUnit_harmony;
	If Missing(wu_diff_amt) Then wu_diff_amt = -writtenUnit_HyFi_sas;
*/
writtenUnit_HyFi_sas=round(writtenUnit_HyFi_sas,0.0001);
writtenUnit_harmony=round(writtenUnit_harmony, 0.0001);


if not missing(writtenUnit_HyFi_sas) and not missing(writtenUnit_harmony) then
do;
     if writtenUnit_HyFi_sas eq 0 then wp_diff_pct = 0.0000;
     else wp_diff_pct = round((writtenPremium_harmony / writtenPremium_HyFi_sas) - 1,0.00001); 
end;

run;
3 REPLIES 3
ballardw
Super User

How is this different than your other basically identical question in https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-deal-with-percentage-when-the-denominator...  

 

What sort of "solution" are you looking for? The DIVIDE function is possibly the easiest but if that doesn't meet your need then describe what is needed.

 

BTW. Post the CODE as well as the messages from the log. That way we would have a chance of knowing just which line(s) of code are referenced in "NOTE: Division by zero detected at line 453 column 55.". It also helps to post the log into a text box to preserve formatting as otherwise "column 55" may not be clear.

 

If you are going to use the / , division operator, it is up to you prevent division by zero by testing for that before the division. The possible overflow conditions with very small values are bit harder to prevent with simple if/then/else which is why SAS provides the DIVIDE function.

PaigeMiller
Diamond | Level 26

@ballardw wrote:

How is this different than your other basically identical question in https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-deal-with-percentage-when-the-denominator...  

 

What sort of "solution" are you looking for? The DIVIDE function is possibly the easiest but if that doesn't meet your need then describe what is needed.


I already asked in that other thread what solution was needed, but no answer was forthcoming. In my mind, it all depends on what you plan to do with this data where some of the percents have 0 in the denominator. In my mind, this isn't a coding problem, it is a problem where @alepage needs to figure out what the right answer is for his situation (possibly with help from us). Then coding is pretty simple.

--
Paige Miller
FreelanceReinh
Jade | Level 19

Hello @alepage,

 


@alepage wrote:

(...)

if not missing(writtenUnit_HyFi_sas) and not missing(writtenUnit_harmony) then
do;
     if writtenUnit_HyFi_sas eq 0 then wp_diff_pct = 0.0000;
     else wp_diff_pct = round((writtenPremium_harmony / writtenPremium_HyFi_sas) - 1,0.00001); 
end;

run;

It is good practice to check for missing values and zero denominators before dividing two numbers. Your code above has all the necessary IF-THEN/ELSE statements for those checks, but then surprisingly divides the values of two variables which were not checked in the IF conditions.

 

The code would look much more consistent -- and, most importantly, avoid the "division by zero" problem -- with

  • either writtenUnit_harmony / writtenUnit_HyFi_sas in the division
  • or writtenPremium_harmony and writtenPremium_HyFi_sas, respectively, in the IF conditions.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 3 replies
  • 294 views
  • 0 likes
  • 4 in conversation