DATA Step, Macro, Functions and more

catching errors in batch

Reply
Contributor
Posts: 73

catching errors in batch

I am updating some code that is executed in batch early in the morning

I'm trying to modify the batch program to catch certain errors and terminate the run.

I've seen where you can send a sysparm value to SAS from the batch command to control how SAS runs but can you send anything back to batch from SAS (running on windows)?

I know about getting the ERRORLEVEL from the execution but I am more interested in specific parts of code.  For example, once and a while a libname to an ODBC data source fails  (never been able to figure out why).  If that happens I would like to catch the situation and force batch to stop the batch program

Valued Guide
Posts: 3,208

Re: catching errors in batch

Your desired behavior is a SAS system option, SAS(R) 9.3 System Options: Reference, Second Edition (error checking strict)

---->-- ja karman --<-----
Contributor
Posts: 73

Re: catching errors in batch

I don't think that will work.  I don't need only the affected SAS program to end but the following that are kicked off in the batch file

I also want to capture what the error is and control what happens next depending on the error

Super User
Super User
Posts: 6,502

Re: catching errors in batch

You might have some control over the error code value sent by SAS back to the operating system using the ABORT statement.

If you need to pass more information back to the script that is calling SAS then you will need to define a location for SAS to write the information, such as a text file.

Regular Contributor
Posts: 217

Re: catching errors in batch

What you want can be accomplished.  In the 90's, when we had jobs stopping mid process, we made them not kick off future jobs and email us with all the particulars when the process stopped.  Most of the methods we used were found in User group Papers and SAS documents.  I bet you can find what you need if you Google it.  We used stop and notify methods because we had jobs running on the mainframe downloading SAS data to UNIX.  If any part of the process failed, we had to stop the remaining processes. Unfortunately I do not have copies of the coding.  The best way to begin is by changing your code to write your logs to datasets.  Then insert code at the end of each process step, that checks the dictionary tables to verify that the previious step created a dataset with more than zero obs.  After that we created a macro variable that held a "stop" or "go" value.  If the macro variable was a go, we processed the next step.  %put statements wrote the stop and go values to the log dataset.  If the macro was a stop, we emailed ourselves a note saying that the job did not run to normal completion.

Contributor
Posts: 73

Re: catching errors in batch

OK....what do I need here to get trap the error in dataset test?

%macro test;

  data junk; set jjjjjjj;

  run;

  data test;

  /* trap error here */

  output;

  run;

  %mend test;

  %test;


Contributor
Posts: 73

Re: catching errors in batch

never mind

%include rpt_bad;

  %macro test;

  /* trap error here */

  %if &syserr %then %do;

  %let error=&syserr;

  /* code to process error conditgion here */

  run;

  %put &error;

  %end

  %mend test;

 

%test;

Respected Advisor
Posts: 3,777

Re: catching errors in batch

I would look into a driver SAS job that uses SYSTASK to run the batch programs.  SYSTASK has options to capture the completion status among other things as I recall.  So depending on the status from jobA you can decide what to do the job B C and D...

Contributor
Posts: 73

Re: catching errors in batch

I am debating using a master.sas program that controls all the other code

A master program would permit better control

The code runs fine most days but problems occur of and on and failures are not common

Valued Guide
Posts: 3,208

Re: catching errors in batch

What will happen with this option is:

-  the running program will detect an error and set the errorlevel to nonzero

- going into syntax-mode nothing else will be execute as follow up

- the log file of this program will still be created. You can still see all things there

- As you should have you scheduling setup recognizing the errorlevel, what is your issue on that?

When you want the detect the succesfull completion of a libname that is another approach

That is not having error detection done by the SAS system but by yourself. Could be a smarter solution.

syslibrc is giving the status of a libname attempt SAS(R) 9.3 Macro Language: Reference.

You will have to code a macro for your logic what to do next

---->-- ja karman --<-----
Ask a Question
Discussion stats
  • 9 replies
  • 684 views
  • 0 likes
  • 5 in conversation