Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to make SAS stop upon the first warning or error?

Tags:

SAS likes to continue processing well after warnings and errors, so I often need to scroll back through pages in the log to find an issue. Is there a better way? I'd like it to stop as soon as the first error or warning appears so I can fix it and try again.

like image 722
Two Bit Gangster Avatar asked Jan 25 '12 19:01

Two Bit Gangster


People also ask

How do I interrupt in SAS?

You can click on the Break toolbar button (the circled exclamation point (!)) or press CTRL+BREAK to interrupt processing in your SAS session.

How do you add a warning in SAS?

USING A PUT STATEMENT TO ADD ERRORS AND WARNINGS TO THE LOG It's easy to add ERROR and WARNING statements to the SAS log. Many of us have used PUT within a data step to write a message to the log. Any time we type “WARNING:” with all capitals and the colon, anything else on that line in the log will be colored green.

How do you stop a macro execution in SAS?

If you are using macros, you can exit a macro smoothly with %abort as long as you either use no options or only use cancel . Depending on what you're doing, you might set up your code to run in a macro (or macros) and use this option (although with the disadvantage of losing some log clarity).


2 Answers

The ERRORS=1 option was previously suggested, but that only stops he ERROR messages from writing to the log. I would suggest another system option ERRORABEND which will stop the program from further processing for most errors. I don't know of an option to terminate processing due to warnings, but I think that you could add a macro like the following to stop processing.

%macro check_for_errors;    %if &syserr > 0 %then %do;       endsas;    %end; %mend check_for_errors;  data test1;     <data step code> run; %check_for_errors; 

You could repeat the macro call after each step of your program, and it should terminate at the point that the error code is anything but 0.

like image 137
RWill Avatar answered Dec 24 '22 11:12

RWill


I've been using the %runquit macro recently. Works well for both batch jobs and interactive sessions (doesn't close your session, just stops running the code).

Source: http://www.cpc.unc.edu/research/tools/data_analysis/sas_to_stata/sas-macros/runquit.html

To use it you basically type %runquit; at the end of any data step or PROC instead of typing your regular run or quit statement.

Code:

%macro runquit;   ; run; quit;   %if &syserr. ne 0 %then %do;      %abort cancel;   %end; %mend runquit; 

Datastep usage:

data something;   * do some stuff; %runquit; 

PROC usage:

proc sql;    * do some stuff; %runquit; 

It's not quite as pretty when reading through code, but it does make debugging a lot easier.

like image 31
Robert Penridge Avatar answered Dec 24 '22 11:12

Robert Penridge