Hi All,
I utilize the below macro to check for errors and abort the run (but not close the session) if an error is encountered. I use SAS EG. The macro is called at the end of each selected data or proc step ( "%Runquit;" instead of "run;" ). The problem I'm having is that SAS aborts not only when there is an error encountered, but also if there is a warning (particularly "variable reference not resolved" warning).
Can anyone help me with the code so that SAS doesn't abort if there is a warning, only when an error is encountered?
Thanks so much in advnance.
%Macro Runquit; /* create a macro to use at end of data and proc steps. */
; run; quit;
%if &syserr. ne 0 %then %do ;
%abort cancel;
%end;
%Mend Runquit ; /* if error is encountered, this macro will stop running the entire program but won't close the session */
Try
%if %eval(&syserr > 4)
Syserr has a relatively large number of possible reported values depending on which procedures are involved. We want to use a numeric comparison becuase in default macro processor is a text based system and in text 10 is not greater than 4. From the documentation on SYSERR you see these values of warning or error codes which would not be less than 4 in text comparisons (9999 would but you should get the gist)
108 | Problem with one or more BY groups |
112 | Error with one or more BY groups |
116 | Memory problems with one or more BY groups |
120 | I/O problems with one or more BY groups |
The following table contains error return codes. The codes do not indicate any specific problems. These codes are guidelines to identify the nature of a problem.
.
I think one could safely omit %EVAL in this case, because: "All parts of the macro language that evaluate expressions (for example, %IF and %DO statements) call %EVAL to evaluate the condition." (documentation of %EVAL function)
If you don't want to trigger an error, you can also look at this, though it was created before %abort was available, so is mostly obsolete now.
Also note that some warnings really should be notes, like
The intervals on the axis labeled xxx are not evenly spaced
TITLE1 is too long. Height has been reduced ...
while some notes really should be warnings, like
Invalid numeric data, XXXX=yyyy, at line X column X.
Invalid argument to function XXX at line XXX column XXX.
Library XXX does not exist.
MERGE statement has more than one data set with repeats of BY values.
Division by zero detected at line XXX column XXX
Mathematical operations could not be performed at the following places
Interactivity disabled with BY processing
SAS went to a new line when INPUT statement reached past the end of a line
Some warnings were later on made into notes, like
Compressing data set xxx increased size by yyy percent.
I wish the rest was reassigned as well....
@ChrisNZ The (undocomented) system option dsoptions=note2err will turn a bunch of those bad notes into errors.
Unfortunately it does not catch the library does not exist note. I keep thinking there may be a dedicted system option for turning this note into a warning or error, but I can't find it. Would be nice. Doesn't catch merge with duplicate BY variables either.
I tend to put more faith in log scanning than these error codes, since in log scanning I can decide to treat unusual notes as errors (I have a white list of acceptable notes, rather than a black list of bad notes). I end jobs with a log scan, but of course wouldn't want to log scan after every step.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.