BookmarkSubscribeRSS Feed
ganeshsas764
Obsidian | Level 7

Hi Team,

 

I need help, 

 

I need to stop the SAS code execution based on error. 

 

I have a SAS report, when I executing code by manually I need to stop the code if any error occurs during the data step or proc step, the code should be stopped at a time without the run remaining steps and the code should not close.  

 

Thanks & Regards

A Ganesh

 

6 REPLIES 6
r_behata
Barite | Level 11

Try :

 

options errorabend;
SASKiwi
PROC Star

The ERRORABEND option is a good one to use but is only useful for SAS batch jobs. It will immediately close your SAS session so unless you are running a batch job you will lose your SAS log and outputs so far.

ganeshsas764
Obsidian | Level 7
If I use ERRORABEND in open code .. automatically sas session will close ..but i need to stop code with out closing session
SASKiwi
PROC Star

If you are after a simple solution then try options SYNTAXCHECK. Your session will remain open but remaining code will run but not process any data (OBS is set to 0). Not quite what you want you could well find it useful.

Kurt_Bremser
Super User

Wrap the code you don't want to execute in case of errors into this:

%if &syscc. = 0 %then %do;

/* code *

%end;

It is possible to use %IF like this in open code (outside a macro) since 9.4M5 (at least).

ChrisNZ
Tourmaline | Level 20

 

Sadly this simple feature has been requested for as long as I remember, and SAS never did anything. 

 

Follow the link for a nasty workaround.

 

Another way is to use

%abort cancel; 

or

data t; abort cancel; run;

 

You have to test manually though.

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 2139 views
  • 3 likes
  • 5 in conversation