07-19-2016 11:43 AM
The requirment is
As the user executes a program, and it produces the output, a predefined macro executes after the program and exports the output to a database.
It works fine when there is no error in the program executyed.
But even if there is an error in the code, I need to execute a macro and should export the erroranous output to a database for review.
Kindly let know if there is any way that I can do it, with out closing the current SAS Session.
07-19-2016 12:13 PM
This is not a trivial issue but you could include in macro after EVERY step that you are concerned with something that can check the value of the automatic SYSERR macro variable. But not all procedures will set the variable.
The generic layout of the macro would look something like:
%if &Syserr > 6 %then %do;
/* what ever you would do when the procedure generated an error*/
/* what ever when the procedure terminates normally*/
Note that the value you check for Syserr might want to be > 4 if you include Abort or Cancel statements in your code. Note that there are many codes possible returned by SYSERR, check your documentation.
07-19-2016 01:15 PM
What should happen if there is no output dataset? More to the point, why is there errors in the code? If there is a situation where things might not happen as you expect then you should be doing "defensive programming", i.e. programming to cover the possible issues. Say no dataset is creted by one step, then using the exists() function you can check to see if it exists, and if not create an empty dataset. Fix and handle your errors in the code and then this problem becomes moot.