04-08-2014 11:10 AM
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
04-08-2014 01:10 PM
Your desired behavior is a SAS system option, SAS(R) 9.3 System Options: Reference, Second Edition (error checking strict)
04-08-2014 01:25 PM
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
04-08-2014 01:32 PM
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.
04-08-2014 01:47 PM
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.
04-08-2014 04:03 PM
OK....what do I need here to get trap the error in dataset test?
data junk; set jjjjjjj;
/* trap error here */
04-08-2014 04:28 PM
/* trap error here */
%if &syserr %then %do;
/* code to process error conditgion here */
04-08-2014 01:36 PM
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...
04-08-2014 02:19 PM
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
04-08-2014 01:39 PM
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