BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Bottoni
Fluorite | Level 6

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;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

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;

 

View solution in original post

5 REPLIES 5
mkeintz
PROC Star

Put the PROC SQL statement after the %end.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Bottoni
Fluorite | Level 6
Thank you for the answer. The program is working perfectly!
Haikuo
Onyx | Level 15

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;

 

Patrick
Opal | Level 21

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".

Bottoni
Fluorite | Level 6
I've tryed it. Doesn't work in the company where I work. SAS Administrators say it doesn't work because there the app is virtualized.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 17854 views
  • 4 likes
  • 4 in conversation