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

 

i have below simple code but want to trick it to run it once every minute + count run + max run is 5 + and put message (max run reached) in log once max run (i.e. 5) reached how i do it? i tried different way but error is "statement is out of proper order" 

 

 

%do %until (condition);
data _null_;
rc=SLEEP(60*1);
run;
%END;

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

@elisas wrote:

actually, this link is awesome solution but (example) i want to run condition only 3 times in 15 minutes (each execution happens 5 min apart) and then stop. once 3 execution completes, put message in log "reached max execution".   

 

https://communities.sas.com/t5/SAS-Programming/SAS-MACRO-WITH-SLEEP-FUNCTION/td-p/314327

 

 


Thanks, this helps to understand what and why

 

%MACRO FINDIT;  
    %let count=0;
    %let condition=0;
	%DO %UNTIL(&condition or &count=3);
               %let condition=%SYSFUNC(FILEEXIST(&TESTFILE));
                %let count=%eval(&count+1);
         %if not &condition %then %do;
		data _null_;
		rc=SLEEP(300);
		run;
          %end;	         
            %if &condition %then %do;
	    PROC SQL;
 	    CREATE TABLE WORK.TESTE AS 
	    SELECT *
	    FROM WORK.TB_SAIDA_GPC;
	    QUIT;
        %end;	
	%END;
        %if &count=3 and not &condition %then %put MAX 3 attempts, file not found;
%MEND;                                         
    
%FINDIT;

Sorry for the poor formatting of the code, I'm lazy today.

--
Paige Miller

View solution in original post

10 REPLIES 10
PaigeMiller
Diamond | Level 26

Please provide more context and more explanation and more detail of this:

 

run it once every minute + count run + max run is 5 + and put message (max run reached) in log once max run (i.e. 5) reached

Also, if you want it to run 5 times, why not just use

 

rc=SLEEP(60*5);

 

 

--
Paige Miller
elisas
Calcite | Level 5

actually, this link is awesome solution but (example) i want to run condition only 3 times in 15 minutes (each execution happens 5 min apart) and then stop. once 3 execution completes, put message in log "reached max execution".   

 

https://communities.sas.com/t5/SAS-Programming/SAS-MACRO-WITH-SLEEP-FUNCTION/td-p/314327

 

 

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

sleep should be used in a better manner than how your request is proposing to use it.  As a mannager I would want to know what you are doing while the process sleeps.  Are you working on another task or just waiting for that process to complete before moving on in your duties.

 

 

Patrick
Opal | Level 21

@elisas 

Often when people are trying to set up such a repeated loop, they want to implement some process which waits until a certain condition becomes true (like: a file exists for further processing).

Why don't you explain us what you're actually trying to achieve (big picture) so we can propose an appropriate solution.

PaigeMiller
Diamond | Level 26

@elisas wrote:

actually, this link is awesome solution but (example) i want to run condition only 3 times in 15 minutes (each execution happens 5 min apart) and then stop. once 3 execution completes, put message in log "reached max execution".   

 

https://communities.sas.com/t5/SAS-Programming/SAS-MACRO-WITH-SLEEP-FUNCTION/td-p/314327

 

 


Thanks, this helps to understand what and why

 

%MACRO FINDIT;  
    %let count=0;
    %let condition=0;
	%DO %UNTIL(&condition or &count=3);
               %let condition=%SYSFUNC(FILEEXIST(&TESTFILE));
                %let count=%eval(&count+1);
         %if not &condition %then %do;
		data _null_;
		rc=SLEEP(300);
		run;
          %end;	         
            %if &condition %then %do;
	    PROC SQL;
 	    CREATE TABLE WORK.TESTE AS 
	    SELECT *
	    FROM WORK.TB_SAIDA_GPC;
	    QUIT;
        %end;	
	%END;
        %if &count=3 and not &condition %then %put MAX 3 attempts, file not found;
%MEND;                                         
    
%FINDIT;

Sorry for the poor formatting of the code, I'm lazy today.

--
Paige Miller
elisas
Calcite | Level 5

sorry but quick follow up question, if my "condition" is date (if today's date=date from table), how can i interpret, "condition" lines in your code (i tried to put quotation mark around but didn't work). Receiving error like "ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:
not &condition "?

 

 

    %let condition=0;
	%DO %UNTIL(&condition or &count=3);
               %let condition=%SYSFUNC(FILEEXIST(&TESTFILE));
               
         %if not &condition %then %do;
		         
            %if &condition %then %do;
	   
        %if &count=3 and not &condition

 

 

 

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

That's a lot of wasted time and resources that could be handled in a better manner.

 

what you going to do if the file had errors and the other user reran the process?  are you checking the modified dates, accessed dates, created dates?

 

You might want to take this one back to the drawing board.

 

Astounding
PROC Star

For starters:

 

  • You are using macro programming statements.  Did you actually define a macro?
  • What is the condition in parentheses?
  • Where is any logic to count the number of iterations?
DWilson
Pyrite | Level 9

The default time unit for the SLEEP function is different between windows and LinuxUnix.

 

Under windows the default time unit is 1 SECOND. Under Linux the default time unit is 1 MILLISECOND.

 

To avoid this issue, specify the time unit in the call to SLEEP:

 

e.g.;

SLEEP(100,1)

 

tells SAS to sleep for 100 seconds on both Windows and Linux/Unix.

 

 

 

elisas
Calcite | Level 5

Thanks a lot Miller. I tested it two ways, positive/negative scenario and it worked fine.

Don't worry about formatting, you knows SAS EG has cool formatting option, right click in program editor and select "format code"   

 

@ Wilson, if i keep sleep (300), it seems working fine, i am running in linux. 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 10 replies
  • 4683 views
  • 2 likes
  • 6 in conversation