DATA Step, Macro, Functions and more

SAS MACRO WITH SLEEP FUNCTION

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 9
Accepted Solution

SAS MACRO WITH SLEEP FUNCTION

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;

 

 


Accepted Solutions
Solution
‎03-28-2017 12:13 PM
Respected Advisor
Posts: 3,124

Re: SAS MACRO WITH SLEEP FUNCTION

[ Edited ]

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


All Replies
Valued Guide
Posts: 797

Re: SAS MACRO WITH SLEEP FUNCTION

Put the PROC SQL statement after the %end.

Occasional Contributor
Posts: 9

Re: SAS MACRO WITH SLEEP FUNCTION

Thank you for the answer. The program is working perfectly!
Solution
‎03-28-2017 12:13 PM
Respected Advisor
Posts: 3,124

Re: SAS MACRO WITH SLEEP FUNCTION

[ Edited ]

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;

 

Respected Advisor
Posts: 3,890

Re: SAS MACRO WITH SLEEP FUNCTION

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

Occasional Contributor
Posts: 9

Re: SAS MACRO WITH SLEEP FUNCTION

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.
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 1408 views
  • 3 likes
  • 4 in conversation