BookmarkSubscribeRSS Feed
vomer
Obsidian | Level 7

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!

8 REPLIES 8
Haikuo
Onyx | Level 15

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

vomer
Obsidian | Level 7

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.

Haikuo
Onyx | Level 15

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

LinusH
Tourmaline | Level 20

"...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
art297
Opal | Level 21

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.

jemmat
Calcite | Level 5

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

options errorabend;

   <more sas code>

Hima
Obsidian | Level 7

Aborts from SAS session

DATA TEST1;

SET TEST;

IF <CONDITION> THEN ABORT ABEND 123;

RUN;

DMartin
Calcite | Level 5

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.

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 8 replies
  • 10281 views
  • 3 likes
  • 7 in conversation