SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

How do I prevent ever having OBS=0, even though an error occur.

I am not looking for a setting after or in each step, but a general statement preventing SAS in setting OBS=0.

 

If a SAS job in a series of SAS jobs fail i.e. &syserrortext. isn't empty, then I report/write an error message to a log. However, when an error occur then automatically SAS set OBS=0, and nothing is written to the log.

 

Best regards

  Jens

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

@JensNielsenXII 

I believe preventing SAS switching into syntaxcheck mode after an Error condition occurs wouldn't write more information about the error to the SAS log but it would continue processing data in downstream steps even after an error. That's normally not what you want to happen.

 

If I understand you right then you could add some logic to your macro to execute after each job some process which writes the job status information to somewhere. In this macro first store away the current values for options syntaxcheck and obs. Then set the options to nosyntaxcheck and obs=max. Write the job status to your table, then reset the options to the values you've saved away.

For storing the options use syntax like: %let sv_syntaxcheck=%sysfunc(getoption(syntaxcheck));

View solution in original post

6 REPLIES 6
Tom
Super User Tom
Super User

I don't understand what you are asking for.  Having OBS option set to zero does not prevent writing to the log.

1     options obs=0;
2     data _null_;
3       put 'ERROR: My custom error message.';
4     run;

ERROR: My custom error message.
data_null__
Jade | Level 19

I think you are asking how to undo when SAS sets OBS=0 and syntax check mode.

 

Try this.  I did not test.  Search for SYNTAXCHECK for more info.

 

Options syntaxcheck=0 obs=MAX;
ballardw
Super User

What type of error? Show examples from the LOG.

JensNielsenXII
Calcite | Level 5

 

Sorry, I should have specified, that the log I am writing to is an external log, a MS SQL table.

 

I have a SAS macro executing different SAS programs, my own or from others. The macro then write the status of the execution to this extermal log (sucess/failure and optionally an error message).

However, if the error initiate an OBS = 0, nothing is written to the log.

As I beforehand don't know where and what kind of error, I need a general prevention of setting OBS = 0.

 

Example:

 

ERROR 76-322: Syntax error, statement will be ignored.

NOTE: The SAS System stopped processing this step because of errors.
NOTE: Due to ERROR(s) above, SAS set option OBS=0, enabling syntax check mode.
This prevents execution of subsequent data modification statements.
WARNING: The data set WORK.BACT may be incomplete. When this step was stopped there were 0
observations and 5 variables.
WARNING: Data set WORK.BACT was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds

 

SASKiwi
PROC Star
options nosyntaxcheck;

Will switch off the setting of OBS = 0.

Patrick
Opal | Level 21

@JensNielsenXII 

I believe preventing SAS switching into syntaxcheck mode after an Error condition occurs wouldn't write more information about the error to the SAS log but it would continue processing data in downstream steps even after an error. That's normally not what you want to happen.

 

If I understand you right then you could add some logic to your macro to execute after each job some process which writes the job status information to somewhere. In this macro first store away the current values for options syntaxcheck and obs. Then set the options to nosyntaxcheck and obs=max. Write the job status to your table, then reset the options to the values you've saved away.

For storing the options use syntax like: %let sv_syntaxcheck=%sysfunc(getoption(syntaxcheck));

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 5665 views
  • 1 like
  • 6 in conversation