Macros for SAS Application Developers
https://github.com/sasjs/core
mp_wait4file.sas
Go to the documentation of this file.
1 /**
2  @file
3  @brief Wait until a file arrives before continuing execution
4  @details Loops with a `sleep()` command until a file arrives or the max wait
5  period expires.
6 
7  Example: Wait 3 minutes OR for /tmp/flag.txt to appear
8 
9  %mp_wait4file(/tmp/flag.txt , maxwait=60*3)
10 
11  @param [in] file The file to wait for. Must be provided.
12  @param [in] maxwait= (0) Number of seconds to wait. If set to zero, will
13  loop indefinitely (to a maximum of 46 days, per SAS [documentation](
14  https://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a001418809.htm
15  )). Otherwise, execution will proceed upon sleep expiry.
16  @param [in] interval= (1) The wait period between sleeps, in seconds
17 
18 
19 **/
20 
21 %macro mp_wait4file(file, maxwait=0, interval=1);
22 
23 %if %str(&file)=%str() %then %do;
24  %put %str(ERR)OR: file not provided;
25 %end;
26 
27 data _null_;
28  maxwait=&maxwait;
29  if maxwait=0 then maxwait=60*60*24*46;
30  do until (fileexist("&file") or slept>maxwait );
31  slept=sum(slept,sleep(&interval,1));
32  end;
33 run;
34 
35 %mend mp_wait4file;