DATA Step, Macro, Functions and more

error checking

Frequent Contributor
Posts: 87

error checking

Is it possible in any case that sas can write out recrds to ouput dataset even with errors (any kind of errors) in the log.

I'm thinking of checking errors by looking at obs > 0 in the final data set. Is there any potential issues with this?

Super User
Posts: 13,583

Re: error checking

Are you looking to send records with errors to a separate data set within a data step? It will depend on the types of 'error' encountered.

There is an automatic variable _ERROR_ in data vector that SAS will set to 1 for most error conditions. You can direct those records to a separate data set with code similar to :

Data NormalProcess Error;

     set have;

<program statements>

     if _error_= 1 then output Error;

     else output NormalProcess;


Super User
Posts: 6,785

Re: error checking

There are two potential issues off the top of my head.

First, the logic of that final DATA step may output zero observations, even if there are no errors.

Second, what if the final DATA step replaces an existing data set?  The final step might contain errors, yet the existing data set would not be replaced because of the errors.  When you check for the number of observations, you will find that observations exist because they were already there before the error-filled DATA step began.

Frequent Contributor
Posts: 87

Re: error checking

Posted in reply to Astounding

Thank you!

Trusted Advisor
Posts: 3,215

Re: error checking

I you want to exclude the possibility of a program or executing error by checking the condition this way it is rather tricky.


- The last processing code need not to be something creating a dataset. Coud be a report processing

- Creating a dataset with 0 record can be the signal of a good processed flow when this dataset is the collection of error records

- When generating reports or flatfiles you are creating not sas-datasets but something else.   

SAS has many ways to validate the processing. The macro sysrc serves as condition code to the OS.

Even that way of checking is not 99,9% reliable. Sometimes you do not get any feedback or it an bug in errorchecking. 

Please can you explain your situation environment and what you are trying to achieve?.   

---->-- ja karman --<-----
Ask a Question
Discussion stats
  • 4 replies
  • 4 in conversation