BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
blakezen
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Try

%if %eval(&syserr > 4)

 

 

View solution in original post

13 REPLIES 13
ballardw
Super User

Try

%if %eval(&syserr > 4)

 

 

blakezen
Obsidian | Level 7
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!
ballardw
Super User

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

 

.

blakezen
Obsidian | Level 7
Thanks so much. This makes everything so much more clear!
FreelanceReinh
Jade | Level 19

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)

blakezen
Obsidian | Level 7
Thanks for the breakout!
blakezen
Obsidian | Level 7
Thank you!
ChrisNZ
Tourmaline | Level 20

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

ChrisNZ
Tourmaline | Level 20

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

 

 

blakezen
Obsidian | Level 7
Thanks so much ChrisNZ!
Quentin
Super User

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

BASUG is hosting free webinars Next up: Jane Eslinger presenting PROC REPORT and the ODS EXCEL destination on Mar 27 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
ChrisNZ
Tourmaline | Level 20
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.
blakezen
Obsidian | Level 7
Thanks so much, this is useful!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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