BookmarkSubscribeRSS Feed
wkossack_nspirehealth_com
Calcite | Level 5

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

9 REPLIES 9
jakarman
Barite | Level 11

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

---->-- ja karman --<-----
wkossack_nspirehealth_com
Calcite | Level 5

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

Tom
Super User Tom
Super User

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.

jwillis
Quartz | Level 8

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.

wkossack_nspirehealth_com
Calcite | Level 5

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;


wkossack_nspirehealth_com
Calcite | Level 5

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;

data_null__
Jade | Level 19

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

wkossack_nspirehealth_com
Calcite | Level 5

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

jakarman
Barite | Level 11

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 --<-----

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 9 replies
  • 3114 views
  • 0 likes
  • 5 in conversation