Stop SAS Program on Error

2019-03-30 01:25发布

问题:

I am using a macro to stop my SAS program on an error, but it always disconnects from the server and then I cannot get back my temporary data sets anymore.

I have tried:

OPTIONS ERRORABEND;

Here is the macro I have tried:

%macro errchk;
%if &syserr >0 and &syserr ne 4 %then %abort;
%mend errchk;

This one keeps processing the following data steps after reaching an error.

I cannot figure out how to stop the rest of the program from running, but NOT disconnect from the SAS server. Any ideas?

回答1:

Have you tried using %goto? Rather than triggering an abort, you can redirect your macro to an exit point, and print something to the log to indicate which part of your code failed.

An example of the syntax is given here:

http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a000209058.htm

I think the problem with %errchk above is probably that the %abort statement applies only to %errchk itself. If you placed %abort calls in the middle of your macro code without wrapping them in another macro you might have more success with that approach. Or you could do something to delay execution of the %abort until %errchk has already completed - perhaps by enclosing it in a %nrstr()? Let me know if this works - I'll be able to test it tomorrow.



回答2:

I can't test this as I don't connect remotely but %ABORT has several optional parameters. Typically I'll use %ABORT cancel; when I use it. Try out each of the additional parameters and see if any of those work.

Link to the %ABORT documentation:

http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a002475061.htm



标签: sas