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;

sas-innovate-2024.png

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.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 3118 views
  • 0 likes
  • 4 in conversation