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
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.
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.
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;
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.