BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
JensNielsenXII
Calcite | Level 5

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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 4740 views
  • 1 like
  • 6 in conversation