Hi Everyone,
This code below runs every minutes at MM:50.
One problem is that the code run inside take about 30 seconds. Thus, when it starts running at 10:50, it will be done at 11:20 and the next run will be 1 minute later, which is 12:50.
Thus, the code will not be run at 11:50.
Can you please help to fix the code to make it runs every MM:50?
Thank you,
HHC
%MACRO RUN_each_MINUTE() ;
%DO %WHILE ( %sysevalf(%sysfunc(time())<'10:00:08't,boolean) ) ;
/****MY CODE ****/
%put %sysfunc(wakeup("%sysfunc(putn(%eval(%sysfunc(intnx(minute,"%sysfunc( time(), time )"t,1))+50),time.))"t));
%end ;
%mend ;
%RUN_each_MINUTE();run;
/*Keep sas sleep here and wake up at next minute at MM:55 to start the loop*/
%put %sysfunc(wakeup("%sysfunc(putn(%eval(%sysfunc(intnx(minute,"%sysfunc( time(), time )"t,1))+40),time.))"t));
%MACRO RUN_each_MINUTE(end) ;
%local t;
%put START;
%DO %WHILE ( %sysevalf(%sysfunc(time())<&end.,boolean) ) ;
%let t = %sysfunc(datetime());
data _null_;call symput ('start_time',put (time(),time.));run;
data a; set sashelp.stocks;run;
data _null_;call symput ('timenow',put (time(),time.));call symput ('datenow',put (date(),date9.));run;
%put start time;%put &start_time;
%put END of RUN;%put &datenow;%put &timenow;
/* sleep for remaining time after execution */
%let t = %sysevalf(60 - (%sysfunc(datetime()) - &t.));
%if %sysevalf(&t. > 0) %then %put %sysfunc(sleep(&t.,1));
%end ;
%put END;
%mend ;
%RUN_each_MINUTE('17:25:08't)
%MACRO RUN_each_MINUTE(end) ;
%local t;
%let t = %sysfunc(second(%sysfunc(datetime())));
%if %sysevalf(&t. > 30)
%then %put %sysfunc(sleep(%sysevalf(90-&t.),1));
%else %put %sysfunc(sleep(%sysevalf(30-&t.),1));
%put START;
%DO %WHILE ( %sysevalf(%sysfunc(time())<&end.,boolean) ) ;
%let t = %sysfunc(datetime());
/****MY CODE ****/
/**/
data _null_;
sleep = sleep(42,1);
run;
/**/
/* sleep for remaining time after execution */
%let t = %sysevalf(60 - (%sysfunc(datetime()) - &t.));
%if %sysevalf(&t. > 0) %then %put %sysfunc(sleep(&t.,1));
%end ;
%put END;
%mend ;
%RUN_each_MINUTE('20:57:08't)
What version of SAS are you running?
In SAS Viya 3.5 and SAS Viya 4 ... this is much easier to accomplish by means of the Job & Flow scheduler.
If you are still running SAS 9.4 Mx (one of the maintenance releases) ... then we will fix your code!
Koen
I am running SAS9.4.
Thanks,
HHC
Usually, I use the SLEEP function for this :
SAS® 9.4 and SAS® Viya® 3.5 Programming Documentation
Functions and CALL Routines
SLEEP
Koen
How about like this:
%MACRO RUN_each_MINUTE(end) ;
%local t;
%put START;
%DO %WHILE ( %sysevalf(%sysfunc(time())<&end.,boolean) ) ;
%let t = %sysfunc(datetime());
/****MY CODE ****/
/*
data _null_;
sleep = sleep(42,1);
run;
*/
/* sleep for remaining time after execution */
%let t = %sysevalf(60 - (%sysfunc(datetime()) - &t.));
%if %sysevalf(&t. > 0) %then %put %sysfunc(sleep(&t.,1));
%end ;
%put END;
%mend ;
%RUN_each_MINUTE('17:25:08't)
Bart
Hi Yabwon,
Can you make your code run at MM:30?
Thanks,
HC
%MACRO RUN_each_MINUTE(end) ;
%local t;
%let t = %sysfunc(second(%sysfunc(datetime())));
%if %sysevalf(&t. > 30)
%then %put %sysfunc(sleep(%sysevalf(90-&t.),1));
%else %put %sysfunc(sleep(%sysevalf(30-&t.),1));
%put START;
%DO %WHILE ( %sysevalf(%sysfunc(time())<&end.,boolean) ) ;
%let t = %sysfunc(datetime());
/****MY CODE ****/
/**/
data _null_;
sleep = sleep(42,1);
run;
/**/
/* sleep for remaining time after execution */
%let t = %sysevalf(60 - (%sysfunc(datetime()) - &t.));
%if %sysevalf(&t. > 0) %then %put %sysfunc(sleep(&t.,1));
%end ;
%put END;
%mend ;
%RUN_each_MINUTE('20:57:08't)
Thank you so much for helping!
HHC
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.