Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
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 @sasjslint {"maxLineLength": 100}
20**/
21
22%macro mp_wait4file(file, maxwait=0, interval=1);
23
24%if %str(&file)=%str() %then %do;
25 %put %str(ERR)OR: file not provided;
26%end;
27
28data _null_;
29 maxwait=&maxwait;
30 if maxwait=0 then maxwait=60*60*24*46;
31 do until (fileexist("&file") or slept>maxwait );
32 slept=sum(slept,sleep(&interval,1));
33 end;
34run;
35
36%mend mp_wait4file;