BookmarkSubscribeRSS Feed
santosh_pat69
Quartz | Level 8

Hi experts

I need to write a code which should periodically check for a file at particular location and if the file exists the data step should execute

The file is signal file which indicates that the input for the SAS data steps.

I had once written the same  I had used the sleep  function

3 REPLIES 3
SASKiwi
PROC Star

There are already some possible approaches in the "More Like This" discussions in the right-hand column beside your post - I suggest you check these out.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

What I think your asking is: If a file appears in x directory, then batch submit some SAS code.

So it sounds to me like you need scheduler software.  There are many options options out there, and some SAS products have this functionality. 

dcruik
Lapis Lazuli | Level 10

I also agree that if you're scheduling this task to run, it's probably better to use the functionality of the scheduler to check for the file in the directory that you want.  If you don't have that functionality in the scheduler, then this macro can help out.  It simply looks for the file directory and file name, and if it exists, it will import it (you can modify the import code), and if it doesn't exist, you can have it do what you woud like (i.e. send an email, kill the session, etc...).  Hope this helps!

%macro check(file);

%if %sysfunc(fileexist("&file")) %then %do;

 

     proc import datafile="&file"

     out=want dbms=xls replace;

     getnames=yes;

     run; %end;

%else %do;

     /****ADD FUNCTIONALITY YOU WANT IF FILE DOESN'T EXIST****/

     %end;

%mend;

%check(\\filelocation\filename.xls)

You can also add a sleep time on the program if you want it to continue running in the background until the file is available in the directory with the sleep function.

data _null_;

     sleep_time=sleep(300,1);  /**** Let's SAS sleep for 5 minutes ****/

run;

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

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4151 views
  • 0 likes
  • 4 in conversation