DATA Step, Macro, Functions and more

macro %runquit; abort if syserr

Accepted Solution Solved
Reply
Contributor
Posts: 38
Accepted Solution

macro %runquit; abort if syserr

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 */


Accepted Solutions
Solution
‎05-19-2016 12:34 PM
Super User
Posts: 10,500

Re: macro %runquit; abort if syserr

[ Edited ]

Try

%if %eval(&syserr > 4)

 

 

View solution in original post


All Replies
Solution
‎05-19-2016 12:34 PM
Super User
Posts: 10,500

Re: macro %runquit; abort if syserr

[ Edited ]

Try

%if %eval(&syserr > 4)

 

 

Contributor
Posts: 38

Re: macro %runquit; abort if syserr

thank you! that worked perfectly, but can you briefly note to me why that syntax solved my issue? what is %eval(&syserr>4) doing to get my issue resolved.

Thanks again!
Super User
Posts: 10,500

Re: macro %runquit; abort if syserr

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.

Error Code Description
1008 General data problem
1012 General error condition
1016 Out-of-memory condition
1020 I/O problem
2000 Semantic action problem
2001 Attribute processing problem
3000 Syntax error
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.
25000

 

.

Contributor
Posts: 38

Re: macro %runquit; abort if syserr

Thanks so much. This makes everything so much more clear!
Trusted Advisor
Posts: 1,115

Re: macro %runquit; abort if syserr

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)

Contributor
Posts: 38

Re: macro %runquit; abort if syserr

Thanks for the breakout!
Contributor
Posts: 38

Re: macro %runquit; abort if syserr

Thank you!
PROC Star
Posts: 1,561

Re: macro %runquit; abort if syserr

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.

http://support.sas.com/kb/24/825.html

PROC Star
Posts: 1,561

Re: macro %runquit; abort if syserr NOTE: SAS went to a new line

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....

 

 

Contributor
Posts: 38

Re: macro %runquit; abort if syserr NOTE: SAS went to a new line

Thanks so much ChrisNZ!
PROC Star
Posts: 1,231

Re: macro %runquit; abort if syserr NOTE: SAS went to a new line

@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.

PROC Star
Posts: 1,561

Re: macro %runquit; abort if syserr NOTE: SAS went to a new line

Thanks @Quentin Yes it seems everybody has their log scanning routine nowadays. It is bit sad that we need to resort to this because the default behaviour is flawed.
Contributor
Posts: 38

Re: macro %runquit; abort if syserr

Thanks so much, this is useful!
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 13 replies
  • 1056 views
  • 6 likes
  • 5 in conversation