BookmarkSubscribeRSS Feed
natrreb
Calcite | Level 5

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. 

7 REPLIES 7
Ksharp
Super User

Now use %return;  ?

SASKiwi
PROC Star

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.

natrreb
Calcite | Level 5

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


art297
Opal | Level 21

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';

natrreb
Calcite | Level 5

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.  

TimArm
Obsidian | Level 7

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;

art297
Opal | Level 21

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';

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 7 replies
  • 2122 views
  • 0 likes
  • 5 in conversation