DATA Step, Macro, Functions and more

How to execute %include statements based on data set existence in each % include

Reply
New Contributor
Posts: 2

How to execute %include statements based on data set existence in each % include

Hi Guys,

How to execute %include statements based on data set existence in each % include. If data set does not exist in current %include then program has to terminate and trigger a mail as job failure.

%include one;

%include two;

%include three;

%include four;

%include five;

%include six;

%include seven;

%include eight;

%include nine;

%include ten;

run;

Thanks for your suggestions.

PROC Star
Posts: 7,492

Re: How to execute %include statements based on data set existence in each % include

You will get a more complete and probably better answer if you explain more about what you are trying to do, but you can always wrap your desired checks and logic into a macro.  e.g.:

%macro checkds;

  %let continue=1;

  %if %sysfunc(exist(work.test)) %then %do;

    %include "c:\art\include1.sas";

  %end;

  %else %do;

    %let continue=0;

  %end;

  %if &continue. and %sysfunc(exist(work.have)) %then %do;

    %include "c:\art\include2.sas";

  %end;

  %else %do;

    %let continue=0;

  %end;

  %if not(&continue) %then %do;

    data _null_;

      file print;

      put #3 @10 "Data set does not exist";

    run;

  %end;

%mend checkds;

%checkds

As for the code to send an email, take a look at: http://support.sas.com/kb/19/767.html

New Contributor
Posts: 2

Re: How to execute %include statements based on data set existence in each % include

In this program data is processing from one include statement to other include statement (i.e output of first include is an input for second include statement) and finally creates out files with correct data. If any one of the include statement doesn't run properly the final output files has not updated with correct data. so am looking for checkpoints at each include while executing the program.

PROC Star
Posts: 7,492

Re: How to execute %include statements based on data set existence in each % include

Unless I misunderstand what you are trying to accomplish, that is what the suggested code does.  However, it was only written for 2 includes and you would have to expand it for however many you actually have.

Ask a Question
Discussion stats
  • 3 replies
  • 212 views
  • 0 likes
  • 2 in conversation