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.
You can click on the Break toolbar button (the circled exclamation point (!)) or press CTRL+BREAK to interrupt processing in your SAS session.
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.
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).
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With