BookmarkSubscribeRSS Feed
sridatta
Calcite | Level 5

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.

3 REPLIES 3
art297
Opal | Level 21

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

sridatta
Calcite | Level 5

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.

art297
Opal | Level 21

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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1258 views
  • 0 likes
  • 2 in conversation