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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 934 views
  • 1 like
  • 3 in conversation