Help using Base SAS procedures

Periodically check the existence of a file and only if the files exist execute the SAS data step

Reply
Contributor
Posts: 66

Periodically check the existence of a file and only if the files exist execute the SAS data step

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

Super User
Posts: 3,252

Re: Periodically check the existence of a file and only if the files exist execute the SAS data step

Posted in reply to santosh_pat69

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.

Super User
Super User
Posts: 7,955

Re: Periodically check the existence of a file and only if the files exist execute the SAS data step

Posted in reply to santosh_pat69

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. 

Frequent Contributor
Posts: 130

Re: Periodically check the existence of a file and only if the files exist execute the SAS data step

Posted in reply to santosh_pat69

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;

Ask a Question
Discussion stats
  • 3 replies
  • 835 views
  • 0 likes
  • 4 in conversation