BookmarkSubscribeRSS Feed
tomcmacdonald
Quartz | Level 8

How do I tell SAS to exit the program on the first error it encounters? 

6 REPLIES 6
ballardw
Super User

What type of errors are you concerned with? In data step code or procedures? And what would you like to happen when the program stops?

Also is this interactive or in batch mode?

And is the code in an %include file?

 

In a data step you may want to use Abort Cancel;

tomcmacdonald
Quartz | Level 8

>What type of errors are you concerned with?

 

Any error. 

 

>In data step code or procedures?

 

Either

 

>And what would you like to happen when the program stops?

 

Stop executing any process and rollback to the previous state. 

 

>Also is this interactive or in batch mode?

 

Either

 

>And is the code in an %include file?

 

Not the code I'm working on now.

 

Basically in my code one procedure depends on output from another procedure and it seems like wasting time to continue processing if any point in that chain fails. 

ballardw
Super User

I'm not sure what you mean by "rollback to previous state" but most of the serious errors SAS does not replace data sets.

Your requirement for any error in data step or procedure and in both batch or interactive mode is likely not going to be accomplished with a simple line or two of code.

 

For example starting with the some basic Error system options such as ERRORABEND, which will terminate the SAS session, may be appropriate but it will terminate the session and diagnostics from an interactive session may not be available unless you are directing the log to a file. But this only affects errors that would cause an error message and go into syntax check mode. It will not stop for errors such as invalid data read during a data step for example.

 

You also have ERRORBYABEND that will treat BY group errors by ending the SAS program.

These two system options are more appropriate for production jobs that are expected to be error free.

 

You may also need to change setting to the DKRICOND and DKROCOND system options for the behavior of drop, keep and rename statements.

DMSSYNCHK may be appropriate for the SAS windowing environment to tell SAS to enter Syntax checking mode when an error is encountered.

FMTERR option might need to be set to generate an error to halt processing for unfound format references.

VNFERR specifies whether SAS issues and error or warning when BY variables don't exist in multiple datasets used in Set, Merge, Update or Modify statements.

 

The Abort statement in a data step might be needed to halt some types of invalid data errors that don't always terminate a data step but would have to be added to each data step with appropriate conditions such as If _error_ then Abort. But the behavior is somewhat different for windowing and batch mode depending on options on the statement.

 

 

ericgj
Calcite | Level 5

I have a similar need to immediately abort SAS on any error (I am running SAS as a batch job in a subprocess and rely on the return code).  Is there no way to trap for things like invalid data read in a data step?  It's not even recorded as a warning. This seems truly insane and dangerous to me. Please tell me there's a way to tell SAS to treat these as errors or at least warnings??   EDIT: some global way without having to do if _ERROR_ then ABORT ABEND;  in every data step?

 

Thanks,

Eric

SASKiwi
PROC Star

I'm not aware of any such option. I find the default batch job SAS system option SYNTAXCHECK works well for me. The batch job keeps running to completion but doesn't do any processing. I can then get the scheduler to email me if there is an error.

SASKiwi
PROC Star

I would explore the ERRORABEND SAS option as already mentioned by @ballardw. This will work well if you are running your jobs in batch mode as your LOG files will record the processing up to the point of the ABEND.

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
  • 6 replies
  • 3604 views
  • 0 likes
  • 4 in conversation