SAS Programming

DATA Step, Macro, Functions and more
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,

I have a code that runs every minutes.

I want to add to that code a section (which contain quite a few data steps) that should be run every hour at 00:01 (hh:mm). 

Look like this added part could be something a macro inside the big one.

Can you please help me with that?

Many thanks,

HHC

 

%MACRO _BREAK() ;
%DO %WHILE (   %sysevalf(%sysfunc(time())<'16:00:08't,boolean)  ) ;

	/*------ADDED part that run every hour---------*/

	/*My MAIN CODE*/

    %*Sleep until 5 seconds after the start of the next minute ;
    %put %sysfunc(wakeup("%sysfunc(putn(%eval(%sysfunc(intnx(minute,"%sysfunc( time(), time )"t,1))+5),time.))"t));
  %end ;
%mend ;

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
hhchenfx
Rhodochrosite | Level 12

Thank you all.

I think I got it as below.

HHC

%MACRO _BREAK() ;
%DO %WHILE (   %sysevalf(%sysfunc(time())<'16:00:08't,boolean)  ) ;

	/*------ADDED part that run every hour---------*/
		%let now=%sysfunc(time());%let hh=%sysfunc(hour(&now),z2.);%put &now;%put &hh;
		%let mm=%sysfunc(minute(&now),z2.);
		%put &mm;


		%macro run_hourly;
		%if &mm=1 %then %do;
			%put 'HERE we go';
		%end;
		%mend;
		%run_hourly;


	/*My MAIN CODE*/

    %*Sleep until 5 seconds after the start of the next minute ;
    %put %sysfunc(wakeup("%sysfunc(putn(%eval(%sysfunc(intnx(minute,"%sysfunc( time(), time )"t,1))+5),time.))"t));
  %end ;
%mend ;

View solution in original post

5 REPLIES 5
ballardw
Super User

If something needs to run at very specific times I would suggest using an actual scheduling program to start a SAS batch job at the given time.

SASKiwi
PROC Star

What hours does this process need to run for? Continuously, or only for certain hours and / or on certain days?

hhchenfx
Rhodochrosite | Level 12

Hi,

My main code run every minutes.

The added section need to run inside this main code but only need to be executed every hour (instead of every minute).

That's why I will can't schedule that part as a separate job.

Thanks,

HHC

 

SASKiwi
PROC Star

Is your hourly processing related to your "by minute" processing? Does one rely on the other or not?  If there is no interaction between the minute and the hourly processing then running to two separately is an option.

 

Also you didn't really answer my question regarding over what time periods does your process run. Does it run 24 hours per day, every day, or only for certain hours on certain days? The more hours the processing runs, the more robust and reliable it has to be.

hhchenfx
Rhodochrosite | Level 12

Thank you all.

I think I got it as below.

HHC

%MACRO _BREAK() ;
%DO %WHILE (   %sysevalf(%sysfunc(time())<'16:00:08't,boolean)  ) ;

	/*------ADDED part that run every hour---------*/
		%let now=%sysfunc(time());%let hh=%sysfunc(hour(&now),z2.);%put &now;%put &hh;
		%let mm=%sysfunc(minute(&now),z2.);
		%put &mm;


		%macro run_hourly;
		%if &mm=1 %then %do;
			%put 'HERE we go';
		%end;
		%mend;
		%run_hourly;


	/*My MAIN CODE*/

    %*Sleep until 5 seconds after the start of the next minute ;
    %put %sysfunc(wakeup("%sysfunc(putn(%eval(%sysfunc(intnx(minute,"%sysfunc( time(), time )"t,1))+5),time.))"t));
  %end ;
%mend ;

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

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
  • 5 replies
  • 1142 views
  • 1 like
  • 3 in conversation