- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.