Help using Base SAS procedures

Stopping SAS program if an error occurs

Reply
Frequent Contributor
Posts: 117

Stopping SAS program if an error occurs

Hi guys,

is there any code that I can insert in my existing sas program which will stop the sas code from running if an error occurs?

Thanks!

Respected Advisor
Posts: 3,156

Stopping SAS program if an error occurs

Something like:

if _error_=1 then stop;  to stop the current datastep or

if _error_=1 then abort; to stop the SAS session.

Regards,

Haikuo

Frequent Contributor
Posts: 117

Stopping SAS program if an error occurs

Where would I put this?

Basically I want SAS to run the entire program and stop running the code when an error occurs....so that I can look at the log and fix it.

Respected Advisor
Posts: 3,156

Stopping SAS program if an error occurs

if just for debug purpose, you don't need to do anything (no addtional coding needed) except checking your log. Your log will tell you when _error_ has been set to 1, where you just have had an error occurred.

Haikuo

Super User
Posts: 5,428

Stopping SAS program if an error occurs

"...will stop the sas code from running" can mean a lot of things.

Depending on that, and how you are executing the program, there a very many alternatives how write your code.

If a an error occur, in most situations SAS will go into syntax check mode, and the rest of the program will just compile, not execute.

/Linus

Data never sleeps
PROC Star
Posts: 7,471

Stopping SAS program if an error occurs

Another option is to simply add the word ' cancel' after your run statement (see: http://www.listserv.uga.edu/cgi-bin/wa?A2=ind0611A&L=sas-l&P=R18708&D=1&H=0&O=D&T=1 )

That will cause SAS to ONLY look for syntax errors and NOT actually run the code.

Regular Learner
Posts: 1

Stopping SAS program if an error occurs

Use system option errorabend at the very beginning of your code, i.e.

options errorabend;

   <more sas code>

Regular Contributor
Posts: 233

Stopping SAS program if an error occurs

Aborts from SAS session

DATA TEST1;

SET TEST;

IF <CONDITION> THEN ABORT ABEND 123;

RUN;

New Contributor
Posts: 3

Stopping SAS program if an error occurs

If you are running interactively, you might want to look at OPTIONS DMSSYNCHK;

Be warned that (at least IMHO) SAS seriously broke it when they went to SAS 9.2; in SAS 9.1.3 it reset every time you submitted something, making it a very useful option to keep subsequent steps from running if an error occured. In SAS 9.2 if the DMSSYNCHK option is set and an error is caught you have to restart SAS to get it to behave again, which is enough of a p.i.t.a. that I quit using it. Don't know if they fixed that glitch in SAS 9.3.

Ask a Question
Discussion stats
  • 8 replies
  • 3974 views
  • 0 likes
  • 7 in conversation