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

Hi all,

I have been struggling with a stupid question for four hours…I need your help…

It is about the automatic variable _error_. I actually want to use this variable to do debug things. However, I found a weird phenomenon…The procedure did have error and steps were failed to run in my program, however the _error_ was still resolved to be 0, which was different from my thought, 1 .

For example, give you the code as follow

data test;

input x y;

cards;

1 2

3 4

;

data test;

set test;

n=_n_

%put &_error_;

run;

The _error_ was resolved as o in the log window…

106421  data test;

106422  input x y;

106423  cards;

NOTE: The data set WORK.TEST has 2 observations and 2 variables.

NOTE: DATA statement used (Total process time):

      real time           0.00 seconds

      cpu time            0.00 seconds

106426  ;

106427

106428  data test;

106429  set test;

106430  n=_n_

106431  %put &_error_;

0

106432  run;

        ---

        22

ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, <, <=,

              <>, =, >, ><, >=, AND, EQ, GE, GT, IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR,

              ^=, |, ||, ~=.

Could you teach me how to use _error_ in debugging? Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

SAS will set SYSERR macro variable for some types of errors.  But if you want to convert the data step _ERROR_ variable into a macro variable then add code in your data step to do that.  For example the step below will not cause the automatic macro variable SYSERR to be set, but the CALL SYMPUTX will set the user macro variable _ERROR_.

%let _error_=0;

data y;

   input x 3. ;

   if _error_ then call symputx('_error_','1');

cards;

abc

run;

%put syserr=&syserr _error_=&_error_ ;

View solution in original post

8 REPLIES 8
Reeza
Super User

You're missing a semi-colon after _n_, before the put statement.

_error_ is an automatic variable NOT a macro variable.  The following code works, but I'm not sure what you're looking for it to do.

data test;

input x y;

cards;

1 2

3 4

;

data test;

set test;

n=_n_;

put _error_;

run;

Tiny_Kane
Obsidian | Level 7


Hi Reeza,

Thank you for your reply. Actually, I was intentionally missing the the semi-colon after _n_ to make the mistake. Beasue I want to check whether the _errror_ would be changed to 1 in that case. Aftet test, in my example, even through the procedure was stopped because of the error, the _error_ was still showing as 0 in the log file. That was my question, why was not it 1?

In addition, in your revised code, I do not see the PUT statement works in the log file....

Haikuo
Onyx | Level 15

_error_ is a PDV variable that only comes alive when a data step is executed. The error in your example (missing a semicolon) is a syntax error that will be detected in the compiling stage, meaning when this error happens, there is no PDV yet, so it is meaningless to talk about a PDV variable, such as _error_.

Not sure about your agenda, but if your purpose is debugging SAS code, then there are many options that you can use, to start, check this link:

SAS(R) 9.3 Language Reference: Concepts, Second Edition

Thanks,

Haikuo

Tiny_Kane
Obsidian | Level 7

Hi Hai.kuo,

Thank you very much for your explain! Your link is very helpful. Thank you.

Tiny_Kane
Obsidian | Level 7

By the way, yes, I want to do debugging. It really takes me a lot of time to search for debugging methods. Thanks.

Reeza
Super User

What kind of debugging? Automated debugging for programs or debugging techniques for interactive programming?

There's a ton of papers on lexjansen.com with regards to this. 

Tom
Super User Tom
Super User

SAS will set SYSERR macro variable for some types of errors.  But if you want to convert the data step _ERROR_ variable into a macro variable then add code in your data step to do that.  For example the step below will not cause the automatic macro variable SYSERR to be set, but the CALL SYMPUTX will set the user macro variable _ERROR_.

%let _error_=0;

data y;

   input x 3. ;

   if _error_ then call symputx('_error_','1');

cards;

abc

run;

%put syserr=&syserr _error_=&_error_ ;

Tiny_Kane
Obsidian | Level 7

Thank you very much for your explain and the code. Thanks a lot!!

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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