BookmarkSubscribeRSS Feed
jdykstra
Calcite | Level 5

I was curios if i am able to turn the division by zero note to an error. (i.e. NOTE: Division by zero detected at line xx column xx. OR NOTE: Mathematical operations could not be performed at the following places. The results of the operations have been set to missing values.)  For example, I usually use the following options: options varinitchk=error mprint=1 validvarname=v7 missing='' ;  where varinitchk=error is the sort of option I am looking for. 

 

Thanks,

Joe

6 REPLIES 6
unison
Lapis Lazuli | Level 10

If you use divide(a,b) instead of a/b then the case of division by 0 will yield a .I (special missing value -- .I for Inf, .M for -Inf). You can then flag those instances with a variable "myerror":

 

data _null_;

ex1=1/0;
put ex1=;

ex2=divide(1,0);
put ex2=;

myerror = (ex2 in (.I .M));
put myerror=;

run;

 

-unison
jdykstra
Calcite | Level 5

I am more of looking for the program to stop running because of errors. Not just put a new note in the log.  Thanks for the thought though.

data_null__
Jade | Level 19

Maybe NOTE2ERR data statement option.

 

35         data _null_ / note2err;


NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds
      
ERROR: Division by zero detected during the compilation phase, detected at line 36 column 9.
NOTE: The SAS System stopped processing this step because of errors.
36            x = 1/0;
37            run;


38         data _null_ / note2err;
39            d = 0;
40            x = 1/d;
41            run;

ERROR: Division by zero detected at line 40 column 9.
ERROR: Termination due to Floating Point Exception
NOTE: The SAS System stopped processing this step because of errors.
NOTE: DATA statement used (Total process time):
jdykstra
Calcite | Level 5

Is there anyway to apply note2err to a specific note and across all datasets?

unison
Lapis Lazuli | Level 10

option dsoptions=note2err;

 

option dsoptions=note2err;

data _null_;
a=1/0;
run;

 

-unison
data_null__
Jade | Level 19

You can use the internal option  DSOPTIONS=note2err; to apply to all data steps.  I don't know if you can make it specific to division by zero.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 1385 views
  • 2 likes
  • 3 in conversation