BookmarkSubscribeRSS Feed
DMoovendhan
Quartz | Level 8

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

 

3 REPLIES 3
ballardw
Super User

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.

DMoovendhan
Quartz | Level 8

Thanks this was helpful...

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 3 replies
  • 1165 views
  • 1 like
  • 3 in conversation