05-19-2016 12:11 PM
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 ;
%Mend Runquit ; /* if error is encountered, this macro will stop running the entire program but won't close the session */
05-19-2016 12:35 PM
05-19-2016 01:06 PM
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.
|1008||General data problem|
|1012||General error condition|
|2000||Semantic action problem|
|2001||Attribute processing problem|
|4000||Not a valid procedure|
|9999||Bug in the procedure|
|20000||A step was stopped or an ABORT statement was issued.|
|20001||An ABORT RETURN statement was issued.|
|20002||An ABORT ABEND statement was issued.|
05-19-2016 05:44 PM
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)
06-01-2016 06:43 PM
06-01-2016 07:43 PM
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....
06-02-2016 11:56 AM
@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.
06-02-2016 10:25 PM
Need further help from the community? Please ask a new question.