DATA Step, Macro, Functions and more

SYMBOLGEN: Macro variable _EFIERR_ resolves to 0

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

SYMBOLGEN: Macro variable _EFIERR_ resolves to 0

I am wondering why the above referenced macro variable does not set to 1 when it encounters an error and stops processing as in the sample code below. I have deliberately set the filename statement to a non-existent URL. How do I use the _EFIERR_ macro variable in subsequent code when it will not return a value of 1 when SAS processing is stopped? Thank you.

filename _000002 url "%str(xyxp://www.bxb.cats/us/Find-Business-Reviews/name/ALEX+FIGLIOLIA+WATER+SEWER/11215)" debug;

data f nf;
format webpage $32767.;
infile _000002 lrecl=32767 delimiter="><";
input webpage $ @@;
if (prxmatch("/Search Result here!|a href=/i",webpage)) then output f;
if (prxmatch("/did not match any Business Names/i",webpage)) then output nf;
if _ERROR_ then call symput('_EFIERR_',1);
run;

data _null_;
e1=&_EFIERR_;
put e1;
run;


Accepted Solutions
Solution
‎11-07-2013 03:16 PM
Trusted Advisor
Posts: 3,212

Re: SYMBOLGEN: Macro variable _EFIERR_ resolves to 0

Posted in reply to BPrater_cancapital_com

Think in the other way. As the datastep kan fail and never run it is bad idea trying to set as fail indicator.

It is more reliable and sure code to put a value in when everything has processed well as good code will run to the expected end.

So:

%let errstp_stat=1 ;  /* to begin with */         

..

Whatever you run 

  call symput("errstp_stat",0) ; /* on the location when you processing is done ok */

..

%macro err_chk ;

   /* do your proceeding tests, abort or whatever you like. */

%mend;

%err_chk;

This construction Di programmers will recognize when seen the generated code.

---->-- ja karman --<-----

View solution in original post


All Replies
Super Contributor
Posts: 282

Re: SYMBOLGEN: Macro variable _EFIERR_ resolves to 0

Posted in reply to BPrater_cancapital_com

Hi,

Try displaying the value of _ERROR_ in the first data step to make sure it is non zero.

Also, maybe try adding an else to your if statement to assign 0 (zero) to macro variable _EFIERR_ so that it always has a value assigned to it.

Otherwise post the log if it is still not making sense.

Regards,

Amir.

New Contributor
Posts: 4

Re: SYMBOLGEN: Macro variable _EFIERR_ resolves to 0

Thanks.

I tried making the following alteration, but the value of _ERROR_ is never output since the original data step never iterates. Both logs are attached. I guess the basic question is how to understand that a data step has failed and pass that information to subsequent code? The only other thing I can think of is to proc printto the log for that one data step and then scan the log with a prxmatch.

filename _000002 url "%str(xyxp://www.bxb.cats/us/Find-Business-Reviews/name/ALEX+FIGLIOLIA+WATER+SEWER/11215)" debug;

%let _EFIERR_=0;

data f nf;

format webpage $32767.;

infile _000002 lrecl=32767 delimiter="><";

input webpage $ @@;

if (prxmatch("/Search Result here!|a href=/i",webpage)) then output f;

if (prxmatch("/did not match any Business Names/i",webpage)) then output nf;

err=_ERROR_; call symput("err",err);

if _ERROR_ then call symput("_EFIERR_",1);

run;

data _null_;

err='&err';

e1=&_EFIERR_;

put e1;

put err;

run;

Attachment
Attachment
Super User
Posts: 5,498

Re: SYMBOLGEN: Macro variable _EFIERR_ resolves to 0

Posted in reply to BPrater_cancapital_com

To display the macro variables properly, get rid of the final DATA step.  Just write them to the log using:

%put _user_;

Better yet, write values within the first DATA step just before the final RUN statement:

put _all_;

To get a DATA step to keep on running after an error occurs, it sometimes works to reset _ERROR_ yourself.  For example, just before the RUN statement in the first DATA step, add:

_error_=0;

No guarantees as to what results you'll see on that, but it might become a part of the solution.

New Contributor
Posts: 4

Re: SYMBOLGEN: Macro variable _EFIERR_ resolves to 0

Posted in reply to Astounding

In your advice, I did find the SYSERRORTEXT to be of some assistance. The value is blank when the data step runs without error; contains text when the data step fails.

The only problem I found is that it is a read-only attribute so is resistant to manual reset. Any thoughts on that?

Thanks.

Super User
Posts: 5,498

Re: SYMBOLGEN: Macro variable _EFIERR_ resolves to 0

Posted in reply to BPrater_cancapital_com

I think I have seen cases where _EFIERR_ is a reserved name in a DATA step.  Just to be safe, change the last line from this:

if _ERROR_ then call symput('_EFIERR_', 1);

To these two lines:

if _ERROR_ then call symputx('URL_NotFound', 1);

_error_=0;

Note that CALL SYMPUTX will perform the numeric to character conversion without using leading blanks, and without generating a conversion message on the log.

Should be a little more to work with at that point ...

Solution
‎11-07-2013 03:16 PM
Trusted Advisor
Posts: 3,212

Re: SYMBOLGEN: Macro variable _EFIERR_ resolves to 0

Posted in reply to BPrater_cancapital_com

Think in the other way. As the datastep kan fail and never run it is bad idea trying to set as fail indicator.

It is more reliable and sure code to put a value in when everything has processed well as good code will run to the expected end.

So:

%let errstp_stat=1 ;  /* to begin with */         

..

Whatever you run 

  call symput("errstp_stat",0) ; /* on the location when you processing is done ok */

..

%macro err_chk ;

   /* do your proceeding tests, abort or whatever you like. */

%mend;

%err_chk;

This construction Di programmers will recognize when seen the generated code.

---->-- ja karman --<-----
New Contributor
Posts: 4

Re: SYMBOLGEN: Macro variable _EFIERR_ resolves to 0

Thank you Mr Karman. Reversing my thinking was the exact solution. A failed data step can never be relied upon as an indicator of success.

Super Contributor
Posts: 253

Re: SYMBOLGEN: Macro variable _EFIERR_ resolves to 0

Posted in reply to BPrater_cancapital_com

_ERROR_ is not quite what you think it is.  _ERROR_ does not indicate an error that causes the data step to terminate; that wouldn't be checkable except by exclusion (like Jaap suggests).  IE, the moment a SAS data step finds an error that causes it to terminate, it terminates - it doesn't go to the bottom and see if it should do something about it.  There's no TRY/CATCH in SAS.

_ERROR_ indicates data errors, such as division by zero, invalid data provided to a PUT or INPUT, etc.  See SAS(R) 9.2 Language Reference: Concepts, Second Edition for more details.  PROC IMPORT for CSV, where you probably first saw this variable, uses this to identify issues with data formatting (such as if a numeric column contains character values).

If you want to check for actual termination errors, then check &SYSERR, which will be 0 if the last data step worked or nonzero if it failed.  See SAS(R) 9.2 Macro Language: Reference for more details and be aware it's not supported by all procs.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 2103 views
  • 3 likes
  • 5 in conversation