DATA Step, Macro, Functions and more

error in %include

Reply
New Contributor
Posts: 3

error in %include

hi! we have a .sas program that calls  a series of .sas programs.

e.i. %include 'D:\saspgm1.sas';

      %include 'D:\saspgm2.sas';

      %include 'D:\saspgm3.sas;

    when we encounter error in saspgm1.sas the error proliferates to saspgm2.sas and saspgm3.sas. even a simple select statement  (select * from table1) will not execute. we cannot use the %abort statement since we want to execute the rest of the .sas programs even if an error was encountered in the first .sas program. How can we stop the error to propagate?

Help please. Thanks. 

Super User
Posts: 10,023

Re: error in %include

Now use %return;  ?

Super User
Posts: 3,252

Re: error in %include

The behaviour of your programs suggests the SYNTAXCHECK option is on. Run PROC OPTIONS to check this.

If this is set then once there is an error, all subsequent code runs in syntax check mode only and does not execute. Add the statement OPTIONS NOSYNTAXCHECK; at the start of your program to avoid this behaviour.

New Contributor
Posts: 3

Re: error in %include

Hi! Thanks for the reply. syntaxcheck is on upon running the proc options; but we still encountered the same problem even if we added the options nosyntaxcheck; at the start of saspgm2.sas


PROC Star
Posts: 7,471

Re: error in %include

Another alternative: create a macro that you call after each %include.  e.g.:

%macro runquit;

; run; quit;

%if &syserr. ne 0 %then %do;

%abort;

%end;

%mend runquit;

data _null_;

  file "c:\art\saspgm1.sas";

  put "data test; set sashelp.class obs=1;run;";

run;

data _null_;

  file "c:\art\saspgm2.sas";

  put "proc print data=sashelp.class (obs=1);run;";

run;

data _null_;

  file "c:\art\saspgm3.sas";

  put "proc print data=sashelp.class (obs=2);run;";

run;

%include 'c:\art\saspgm1.sas';

%runquit

%include 'c:\art\saspgm2.sas';

%runquit

%include 'c:\art\saspgm3.sas';

New Contributor
Posts: 3

Re: error in %include

Hi sir! when we add the macro runquit in our main sas program and added the %runquit; after every %include as instructed, only the saspgm1.sas was executed. our goal is to execute the rest of the sas programs even if we encountered an error in the first %include . Thanks.  

Contributor
Posts: 29

Re: error in %include

In that case, if you want to reset the syserr value each time, change the %runquit macro to:

%macro runquit;

%* Reset the syserr value;

data _null_;

x=x;

run;

%mend runquit;

PROC Star
Posts: 7,471

Re: error in %include

Did the 2nd to %includes in the example run as intended?

If they did, there might be something in one of your actual %includes that has to be addressed by the macro.  The following alternative might be enough.  It clears out most unfinished business, with the exception of replacing a missing %mend statement in your code:

%macro runquit;

; run; quit;

*))%*))*/;

;;;;

options notes;

run cancel; quit;

proc unk; run;

%if &syserr. ne 0 %then %do;

%abort;

%end;

%mend runquit;

data _null_;

  file "c:\art\saspgm1.sas";

  put "data test; set sashelp.class obs=1;run;";

run;

data _null_;

  file "c:\art\saspgm2.sas";

  put "proc print data=sashelp.class (obs=1);run;";

run;

data _null_;

  file "c:\art\saspgm3.sas";

  put "proc print data=sashelp.class (obs=2);run;";

run;

%include 'c:\art\saspgm1.sas';

%runquit

%include 'c:\art\saspgm2.sas';

%runquit

%include 'c:\art\saspgm3.sas';

Ask a Question
Discussion stats
  • 7 replies
  • 653 views
  • 0 likes
  • 5 in conversation