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
Try :
options errorabend;
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.
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.
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).
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.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.