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 %length(&file)=0 %then %do;
25 %put NOTE: &sysmacroname: no file was provided so it returns immediately;
26 %return;
27%end;
28
29data _null_;
30 maxwait=&maxwait;
31 if maxwait=0 then maxwait=60*60*24*46;
32 do until (fileexist("&file") or slept>maxwait );
33 slept=sum(slept,sleep(&interval,1));
34 end;
35run;
36
37%mend mp_wait4file;