DATA Step, Macro, Functions and more

Execution after encountering error

Reply
Contributor
Posts: 65

Execution after encountering error

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.

 

Regards,

Moovendhan Devaraj

 

Super User
Posts: 11,343

Re: Execution after encountering error

Posted in reply to DMoovendhan

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:

 

%macro t1;

   %if &Syserr > 6 %then %do;

    /* what ever you would do when the procedure generated an error*/

   %end;

   %else %do;

    /* what ever when the procedure terminates normally*/

   %end;

%mend;

 

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.

Contributor
Posts: 65

Re: Execution after encountering error

Thanks this was helpful...

Super User
Super User
Posts: 7,970

Re: Execution after encountering error

Posted in reply to DMoovendhan

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.

Ask a Question
Discussion stats
  • 3 replies
  • 267 views
  • 1 like
  • 3 in conversation