DATA
_NULL_
;
fex=
0
;
DO UNTIL(fex=1
) ;
if %sysfunc(fileexist("C:\temp\fix.txt")) then fex=1
;
else x=sleep(5
);
END
;
RUN
;
hi guys,
when file exist at start, it works!
why does this NOT work when the file does not exist and is created during the sleep loop?
it looks to me that fileexist is only executed once??
Regards,
Herman
Herman,
The comments you've received are on the mark. %SYSFUNC is not part of the DATA step. It merely determines what statements appear in the DATA step. So the DATA step sees:
if 0 then fex=1;
else x=sleep(5);
Creating the file will not change these statements, so SAS ought to cut short on the looping. But removing %SYSFUNC might do the trick.
Good luck.
When the file does not exist, your code will enter infinite loop, cause always fex=0. If file exists, yes, fileexist will exexute once, since there is no set statement, data _null_ will only run it once, no implied loop here.
Also, don't understand why you use %sysfunc, it seems to me unnecessary here, unless you need to deal with macro variables.
Regards,
Haikuo
indeed it will go into a loop UNTIL the file is present in the folder, I'd hoped !!
SAS might have optimized your test out of the loop.
Try putting the filename in a variable so that SAS compiler doesn't view it as a constant.
Herman,
The comments you've received are on the mark. %SYSFUNC is not part of the DATA step. It merely determines what statements appear in the DATA step. So the DATA step sees:
if 0 then fex=1;
else x=sleep(5);
Creating the file will not change these statements, so SAS ought to cut short on the looping. But removing %SYSFUNC might do the trick.
Good luck.
As others have said, you need to get the %SYSFUNC out of this code - it is not necessary. You also do not need the variables FEX or X. On my Windows system, this sample code worked just fine:
DATA _NULL_;
DO UNTIL(fileexist("C:\temp\fix.txt"));
call sleep(5);
END;
RUN;
On unix you would want to alter this just slightly since the default time setting for the sleep function is different than under windows (millisecond on unix vs. second in windows).
data _null_;
do until(fileexist("/temp/fix.txt"));
call sleep(5,1);
end;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.