06-21-2015 03:12 PM
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
06-21-2015 03:36 PM
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.
06-22-2015 06:53 AM
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.
06-22-2015 09:49 AM
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!
%if %sysfunc(fileexist("&file")) %then %do;
proc import datafile="&file"
out=want dbms=xls replace;
/****ADD FUNCTIONALITY YOU WANT IF FILE DOESN'T EXIST****/
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.
sleep_time=sleep(300,1); /**** Let's SAS sleep for 5 minutes ****/