I need to start to process my program only if a file was uploaded in a directory.
I developed a code to verify if the file exist and it works well when the file are in the directory!
When the file doesn't exist I tryed to make the program wait a period of time then process the code again with the sleep function. However it isn't working. The program doesn't wait the specified time.
Sorry for my bad english. Can anyone help me?
SAS code:
%LET TESTFILE = "/usuario/teste/TB_SAIDA_GPC.TXT";
%MACRO FINDIT;
%DO %UNTIL(%SYSFUNC(FILEEXIST(&TESTFILE)));
PROC SQL;
CREATE TABLE WORK.TESTE AS
SELECT *
FROM WORK.TB_SAIDA_GPC;
QUIT;
SLEEP(60);
%END;
%MEND;
%FINDIT;
From SAS manual, it reads "The SLEEP function suspends the execution of a program that invokes this function for a period of time that you specify. The program can be a DATA step, macro, IML, SCL, or anything that can invoke a function. The maximum sleep period for the SLEEP function is 46 days."
So Sleep() can't be used by itself. Try below:
%LET TESTFILE = "/usuario/teste/TB_SAIDA_GPC.TXT";
%MACRO FINDIT;
%DO %UNTIL(%SYSFUNC(FILEEXIST(&TESTFILE)));
data _null_;
rc=SLEEP(60);
run;
%END;
PROC SQL;
CREATE TABLE WORK.TESTE AS
SELECT *
FROM WORK.TB_SAIDA_GPC;
QUIT;
%MEND;
%FINDIT;
Put the PROC SQL statement after the %end.
From SAS manual, it reads "The SLEEP function suspends the execution of a program that invokes this function for a period of time that you specify. The program can be a DATA step, macro, IML, SCL, or anything that can invoke a function. The maximum sleep period for the SLEEP function is 46 days."
So Sleep() can't be used by itself. Try below:
%LET TESTFILE = "/usuario/teste/TB_SAIDA_GPC.TXT";
%MACRO FINDIT;
%DO %UNTIL(%SYSFUNC(FILEEXIST(&TESTFILE)));
data _null_;
rc=SLEEP(60);
run;
%END;
PROC SQL;
CREATE TABLE WORK.TESTE AS
SELECT *
FROM WORK.TB_SAIDA_GPC;
QUIT;
%MEND;
%FINDIT;
You've got already all you need from others to make your current code work.
If available then I personally would go an approach using a scheduler where you trigger your process "on file arrival".
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.