Run an error check to stop SAS


If you want to use RUNQUIT, then feel free to download load it here:




If you are not prompted to "Save To Disk", then right-click the link and choose "Save Link Target As..."  Otherwise, you will need to save the web page to your computer.  Make sure you save the file as a plain text file not an htm/html file.


If you are running SAS 9.2 or higher and want to copy and paste RUNQUIT into the top of all your SAS programs, RUNQUIT can be as simple as:

   %macro runquit;
     ; run; quit;
     %if &syserr. ne 0 %then %do;
        %abort cancel;
   %mend runquit;

Disclaimer:  There is no warranty on this software either expressed or implied.  This program is released under the terms and conditions of GNU General Public License.




Programmer:  Dan Blanchette
Carolina Population Center
University of North Carolina at Chapel Hill
Chapel Hill, NC  USA

Date:  14May2010
Last updated:  08Jun2010

Stop SAS in your interactive Windows SAS session or batch submission when an error occurs without ending your SAS session.


RUNQUIT is a SAS macro that inserts "run;" and "quit;" into your code and does an error check and if an error has occurred it stops SAS from continuing to process the rest of the submitted statements.  You can just type "%runquit;" instead of "run;" or "quit;" in your code so that SAS will stop whenever an error occurs.

For batch SAS users, RUNQUIT inserts "endsas;" into your code when an error occurs and thus stops the program from continuing.

For interactive SAS users running SAS 9 (or higher) RUNQUIT does not end your interactive SAS session when an error occurs.  You will not loose any of your code or data sets.  RUNQUIT invokes the SAS macro %ABORT with the CANCEL option which only cancels submitted statements and writes this in your log for SAS 9.2 or higher: 

ERROR: Execution canceled by an %ABORT CANCEL statement.
NOTE: The SAS System stopped processing due to receiving a CANCEL request.

SAS 9 introduced the %ABORT macro but it did not have the CANCEL option, but "%ABORT cancel;" still stops SAS from processing the rest of your code in an interactive SAS session without terminating your session.  It writes this error message in your log:

ERROR: Unrecognized option on %ABORT statement: cancel
ERROR: Execution terminated by an %ABORT statement

For interactive SAS Windows users running an earlier version of SAS than version 9 on the Windows operating system, RUNQUIT basically presses the Interrupt button (the icon with the exclamation point "!" in a circle in the SAS toolbar): SAS Interrupt Buttuon for you when an error occurs.  When the pop-up window comes up all you have to do is click "OK" two times as long as your default selected answers are: 

1. Cancel Submitted Statements
and in the 2nd pop-up:
Y to cancel submitted statements

For interactive SAS Windows users running an earlier version of SAS than version 9 but not running SAS on the Windows operating system, RUNQUIT pops up a window to pause SAS and to instruct you to click the Interrupt button in your SAS Session Manager:
SAS Session Manager
(which is normally minimized when SAS is invoked).

So, just type: type "%runquit;" instead of "run;" or "quit;" in your code so that SAS will stop whenever an error occurs.

How to use the RUNQUIT macro:

Using the RUNQUIT macro requires that you understand how to use the "%include" SAS statement and that you know how to call a SAS macro.
For example, if you have copied the file to "C:\SASmacros\", then you tell SAS about this macro by adding the following line to your SAS program:
 %include "C:\SASmacros\";

The include statement makes SAS aware of the RUNQUIT macro which is in the file  To use the macro you have to make a call to it.  To do that you add a line like the following to your SAS program:



  %include "C:\SASmacros\"; ** Include macro once in a SAS session and call it **;
                                        *  as many times as you like in that session.     **;

   ** This will generate an error due to an invalid libref: **;
   proc contents;

   ** This proc will not be run: **;
   proc contents;

Wink Plone Theme by Quintagroup © 2013.

Personal tools
This is themeComment for Wink theme