BookmarkSubscribeRSS Feed
mcjs
Fluorite | Level 6

Hi, 

 

My code is something like the following. It is a simple do-loop, and inside the loop, there is a procedure, which generates an output for each loop. 

 

The problem is, the procedure often results in an error (ERROR: Floating Point Overflow. ) from a loop, and if the error is encountered, entire macro is stopped (ERROR: Termination due to Floating Point Exception). I want the macro to continue to proceed to the next loop when an error is resulted from from the procedure of a loop.

 

Any advise? Thank you in advance. 


===============================================
%macro xxx;


%do i = 1 %to 10000.;

 

data _null_;

set fq;

if _n_ = &i.;

call symput('cusip',cusip6);call symput('datadate',datadate);

run;

 

proc nlp data=datain(where = (cusip6 = "&cusip." and datadate = &datadate.))

              out=dataout&i.;
.............

run;

%end;
%mend;

===============================================

12 REPLIES 12
Tom
Super User Tom
Super User

Please show an example of the error and its impact on the rest of the %DO loop.

It shouldn't stop the macro, but perhaps it is setting the system option OBS to zero and this is making the other steps fail?

mcjs
Fluorite | Level 6

The following is log from the error message. At the message, output dataset is PINEST&i. You can see that do-loop stopped at i=801.

I need the macro to proceed to i=802, ignoring the error and no-ouput of i=801. 

===================================

ERROR: Floating Point Overflow.
ERROR: Termination due to Floating Point Exception
NOTE: The SAS System stopped processing this step because of errors.
NOTE: There were 64 observations read from the data set WORK.PIN_DATA.
WHERE (cusip6='006739 ') and (datadate=19996);
WARNING: The data set WORK.PINEST801 may be incomplete. When this step was stopped there were 0
observations and 5 variables.
WARNING: Data set WORK.PINEST801 was not replaced because this step was stopped.
NOTE: PROCEDURE NLP used (Total process time):
real time 0.15 seconds
cpu time 0.12 seconds

===================================

mcjs
Fluorite | Level 6

Hi KurtBremser, 

 

That is exactly why I coded a looping macro by cusip and datadate, rather than "proc nlp...;by cusip datadate;..."

 

I understand proc nlp returns error for some type of data. My question is, even when proc nlp returns an error, why the macro is not proceeding to the next loop. 

 

 

mcjs
Fluorite | Level 6

I am not sure what "syntax check mode" is, but I would like to answer it stops immediately. See the log below.  

===================================================

i = 21449: cusip6 = 829073 and datadate = 19358

NOTE: Your code contains 3 program statements.
NOTE: Gradient is computed using analytic formulas.
NOTE: Hessian is computed using analytic formulas.
ERROR: Floating Point Overflow.
ERROR: Termination due to Floating Point Exception
NOTE: The SAS System stopped processing this step because of errors.
NOTE: There were 69 observations read from the data set WORK.PIN_DATA.
WHERE (cusip6='829073 ') and (datadate=19358);
WARNING: The data set PIN.PINEST21449 may be incomplete. When this step was stopped there were 0
observations and 5 variables.
NOTE: PROCEDURE NLP used (Total process time):
real time 0.18 seconds
cpu time 0.12 seconds

==============================================

This is the last a few lines of log where the macro stops. The first line of the above log is generated by a "%put" command. It shows that the loop stopped at i=21499, while the loop is supposed to run to i=26412. 

mcjs
Fluorite | Level 6

FYI, I am adding entire macro. 

=================================

%macro pin(dsetin = , alpha = , from = , delta = , eta = , mu = );


data _null_;set &dsetin. end = eof;if eof then call symput('num',_n_);run;

 

%local i;
%do i = &from. %to &num.;

 

data _null_;set &dsetin.;if _n_ = &i.;call symput('cusip',cusip6);call symput('datadate',datadate);run;

%put i = &i.: cusip6 = &cusip. and datadate = &datadate.;


proc nlp data=pin_data(where = (cusip6 = "&cusip." and datadate = &datadate.)) noprint
out=pin.pinest&i.(keep = cusip6 datadate ALPHA ETA MU);
by cusip6 datadate;
max loglik;
decvar ALPHA = &alpha., DELTA = &delta., ETA = &eta., MU = &mu.;
M = min(buys,sells) + max(buys,sells) / 2.0 ;
x = eta / (mu + eta) ;
bounds 0.0 < eta mu, 0.0 <= alpha delta <= 1.0 ;
loglik = -2.0 * eta + M * log(x) + (buys + sells) * log(mu + eta) +
log( alpha * (1.0 - delta) * exp(-1.0 * mu) * (x ** (sells - M )) +
alpha * delta * exp(-1.0 * mu) * (x ** (buys - M)) +
(1.0 - alpha) * (x ** (buys + sells - M)) ) ;
run;

 

%if &i. = 1 %then %do;data pinest;set pinest1;run;%end;
%else %do;data pinest;set pinest pin.pinest&i.;run;%end;

 

%end;


%mend;

Kurt_Bremser
Super User

OK, this is peculiar. The macro loop continued in all circumstances I could test with some deliberately crashing code.

Quick and dirty:

%macro create_data;
%do i = 1 %to 3;
data work.class&i;
set sashelp.class;
run;
%end;
%mend;
%create_data
%macro test_data;
%do i = 1 %to 5;
%put i=&i.;
data want;
set work.class&i;
run;
%end;
%mend;
%test_data

I tried several of the errorhandling system options, but the only thing I could come up with is an automatic abend (termination of the SAS process) when the error was encountered. In all other cases, the %do loop continued, and I received a further ERROR message in iteration 5.

 

I would bring this to the attention of SAS technical support, maybe they know something I don't.

mcjs
Fluorite | Level 6

Thanks, KurtBremser. As you commented, maybe it's related to proc nlp. I will contact SAS. 

Tom
Super User Tom
Super User
Check the setting of the ERRORABEND option.
%put %sysfunc(getoption(errorabend));
mcjs
Fluorite | Level 6

See the log as follows:

========================================

899 %put %sysfunc(getoption(errorabend));
NOERRORABEND

Kurt_Bremser
Super User

@Tom wrote:
Check the setting of the ERRORABEND option.
%put %sysfunc(getoption(errorabend));

That was one of my tests, but then the workspace server terminated with a proper final message in the log. A "simple" exit of the %do loop without any further messages, but a still living SAS process did not happen.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 12 replies
  • 2730 views
  • 2 likes
  • 3 in conversation