Loop to check data set exist for 3 days

Posts: 41

Loop to check data set exist for 3 days


My requirement is to check the data set exist in one location. expected date every month 15th need to check up to 18th if data set not placed in that location I need to send mail to client data set not available. pls help me how to achieve this task through loop, arrays or macros.

Occasional Contributor
Posts: 17

Re: Loop to check data set exist for 3 days

The exist() function can be used in data steps (not necessarily data _NULL_Smiley Wink and macros as shown below:

/* in data step */

%let data_exist=0;

data _NULL_;

     if exist("<your dataset>") then do; /* use quotes */

           call symputx("data_exist",1,"G");



/* in macro */

%let data_exist=0;

%macro your_macro;

     %if %sysfunc(exist(<your dataset>)) %then %do; /* no quotes */

           %let data_exist=1;



However, your data set nomenclature and other related criteria is required to further design the looping. Anyway, hope this helps.


Posts: 41

Re: Loop to check data set exist for 3 days

Thanks for help. but how I set the condition to send mail if data set not exist or not present in specified location after 3 days(15-18

th date). I need to check for 3 days if exist then process else send mail.

Respected Advisor
Posts: 3,892

Re: Loop to check data set exist for 3 days

has provided 2 code variations of how to check for existence of a data set.

I would assume what you need to do is to run this code for the relevant time period. You then also would need to maintain a control table to log cases where you've actually found the data set (eg. you find it on the 16th, process it, write an entry to the control table. You run it on the 17th: check the control table and if already run successfully stop any further processing).

So if running on the 18th and there is no new file and you haven't processed it on an earlier date (control table): execute SAS code sending an email. If you "Google" a bit you will find sample code of how to do this.

Ask a Question
Discussion stats
  • 3 replies
  • 3 in conversation