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!
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
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.
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
"...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
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.
Use system option errorabend at the very beginning of your code, i.e.
options errorabend;
<more sas code>
Aborts from SAS session
DATA TEST1;
SET TEST;
IF <CONDITION> THEN ABORT ABEND 123;
RUN;
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 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.