BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
hhchenfx
Rhodochrosite | Level 12

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)
1 ACCEPTED SOLUTION

Accepted Solutions
yabwon
Amethyst | Level 16
%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)
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



View solution in original post

7 REPLIES 7
sbxkoenk
SAS Super FREQ

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

hhchenfx
Rhodochrosite | Level 12

I am running SAS9.4.

Thanks,

HHC

sbxkoenk
SAS Super FREQ

Usually, I use the SLEEP function for this :

 

SAS® 9.4 and SAS® Viya® 3.5 Programming Documentation
Functions and CALL Routines

SLEEP

Koen

yabwon
Amethyst | Level 16

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

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



hhchenfx
Rhodochrosite | Level 12

Hi Yabwon,

Can you make your code run at MM:30?

Thanks,

HC

yabwon
Amethyst | Level 16
%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)
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



hhchenfx
Rhodochrosite | Level 12

Thank you so much for helping!

HHC

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 7 replies
  • 2802 views
  • 0 likes
  • 3 in conversation