<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Run code every minute in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Run-code-every-minute/m-p/911033#M359247</link>
    <description>&lt;P&gt;Usually, I use the SLEEP function for this :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS® 9.4 and SAS® Viya® 3.5 Programming Documentation&lt;BR /&gt;Functions and CALL Routines&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;SLEEP&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Example 1: Suspending Execution for a Specified Period of Time&lt;BR /&gt;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p0a6vn2td7bjr2n1viy8y4lgvq61.htm#p1s7cip9gprevqn1nh8d0gb9iu6d" target="_blank"&gt;https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p0a6vn2td7bjr2n1viy8y4lgvq61.htm#p1s7cip9gprevqn1nh8d0gb9iu6d&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;Example 2: &lt;STRONG&gt;Suspending Execution Based on a Calculation of Sleep Time&lt;/STRONG&gt;&lt;BR /&gt;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p0a6vn2td7bjr2n1viy8y4lgvq61.htm#p0d0sacmewt7c8n0zw8am81bowai" target="_blank"&gt;https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p0a6vn2td7bjr2n1viy8y4lgvq61.htm#p0d0sacmewt7c8n0zw8am81bowai&lt;/A&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
    <pubDate>Tue, 09 Jan 2024 16:50:32 GMT</pubDate>
    <dc:creator>sbxkoenk</dc:creator>
    <dc:date>2024-01-09T16:50:32Z</dc:date>
    <item>
      <title>Run code every minute</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-code-every-minute/m-p/911018#M359242</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;
&lt;P&gt;This code below runs every minutes at MM:50.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;Thus, the code will not be run at 11:50.&lt;/P&gt;
&lt;P&gt;Can you please help to fix the code to make it runs every MM:50?&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

%MACRO RUN_each_MINUTE() ;
%DO %WHILE (   %sysevalf(%sysfunc(time())&amp;lt;'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;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*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())&amp;lt;&amp;amp;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 &amp;amp;start_time;
		%put END of RUN;%put &amp;amp;datenow;%put &amp;amp;timenow;

		  /* sleep for remaining time after execution */
		  %let t = %sysevalf(60 - (%sysfunc(datetime()) - &amp;amp;t.));
		  %if %sysevalf(&amp;amp;t. &amp;gt; 0) %then %put %sysfunc(sleep(&amp;amp;t.,1));

%end ;

%put END;
%mend ;
%RUN_each_MINUTE('17:25:08't)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Jan 2024 20:17:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-code-every-minute/m-p/911018#M359242</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2024-01-09T20:17:15Z</dc:date>
    </item>
    <item>
      <title>Re: Run code every minute</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-code-every-minute/m-p/911028#M359244</link>
      <description>&lt;P&gt;What version of SAS are you running?&lt;/P&gt;
&lt;P&gt;In SAS Viya 3.5 and SAS Viya 4 ... this is much easier to accomplish by means of the Job &amp;amp; Flow scheduler.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are still running SAS 9.4 M&lt;EM&gt;x&lt;/EM&gt; (one of the maintenance releases) ... then we will fix your code!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jan 2024 16:25:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-code-every-minute/m-p/911028#M359244</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2024-01-09T16:25:39Z</dc:date>
    </item>
    <item>
      <title>Re: Run code every minute</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-code-every-minute/m-p/911029#M359245</link>
      <description>&lt;P&gt;How about like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO RUN_each_MINUTE(end) ;
%local t;
%put START;

%DO %WHILE (   %sysevalf(%sysfunc(time())&amp;lt;&amp;amp;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()) - &amp;amp;t.));
  %if %sysevalf(&amp;amp;t. &amp;gt; 0) %then %put %sysfunc(sleep(&amp;amp;t.,1));

%end ;

%put END;
%mend ;

%RUN_each_MINUTE('17:25:08't)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jan 2024 16:27:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-code-every-minute/m-p/911029#M359245</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2024-01-09T16:27:50Z</dc:date>
    </item>
    <item>
      <title>Re: Run code every minute</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-code-every-minute/m-p/911031#M359246</link>
      <description>&lt;P&gt;I am running SAS9.4.&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jan 2024 16:42:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-code-every-minute/m-p/911031#M359246</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2024-01-09T16:42:36Z</dc:date>
    </item>
    <item>
      <title>Re: Run code every minute</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-code-every-minute/m-p/911033#M359247</link>
      <description>&lt;P&gt;Usually, I use the SLEEP function for this :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS® 9.4 and SAS® Viya® 3.5 Programming Documentation&lt;BR /&gt;Functions and CALL Routines&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;SLEEP&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Example 1: Suspending Execution for a Specified Period of Time&lt;BR /&gt;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p0a6vn2td7bjr2n1viy8y4lgvq61.htm#p1s7cip9gprevqn1nh8d0gb9iu6d" target="_blank"&gt;https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p0a6vn2td7bjr2n1viy8y4lgvq61.htm#p1s7cip9gprevqn1nh8d0gb9iu6d&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;Example 2: &lt;STRONG&gt;Suspending Execution Based on a Calculation of Sleep Time&lt;/STRONG&gt;&lt;BR /&gt;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p0a6vn2td7bjr2n1viy8y4lgvq61.htm#p0d0sacmewt7c8n0zw8am81bowai" target="_blank"&gt;https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p0a6vn2td7bjr2n1viy8y4lgvq61.htm#p0d0sacmewt7c8n0zw8am81bowai&lt;/A&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jan 2024 16:50:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-code-every-minute/m-p/911033#M359247</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2024-01-09T16:50:32Z</dc:date>
    </item>
    <item>
      <title>Re: Run code every minute</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-code-every-minute/m-p/911036#M359248</link>
      <description>&lt;P&gt;Hi Yabwon,&lt;/P&gt;
&lt;P&gt;Can you make your code run at MM:30?&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;HC&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jan 2024 17:34:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-code-every-minute/m-p/911036#M359248</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2024-01-09T17:34:25Z</dc:date>
    </item>
    <item>
      <title>Re: Run code every minute</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-code-every-minute/m-p/911041#M359250</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO RUN_each_MINUTE(end) ;
%local t;

%let t = %sysfunc(second(%sysfunc(datetime())));
%if %sysevalf(&amp;amp;t. &amp;gt; 30)
    %then %put %sysfunc(sleep(%sysevalf(90-&amp;amp;t.),1));
    %else %put %sysfunc(sleep(%sysevalf(30-&amp;amp;t.),1));


%put START;
%DO %WHILE (   %sysevalf(%sysfunc(time())&amp;lt;&amp;amp;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()) - &amp;amp;t.));
  %if %sysevalf(&amp;amp;t. &amp;gt; 0) %then %put %sysfunc(sleep(&amp;amp;t.,1));

%end ;

%put END;
%mend ;

%RUN_each_MINUTE('20:57:08't)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Jan 2024 19:58:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-code-every-minute/m-p/911041#M359250</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2024-01-09T19:58:03Z</dc:date>
    </item>
    <item>
      <title>Re: Run code every minute</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-code-every-minute/m-p/911043#M359251</link>
      <description>&lt;P&gt;Thank you so much for helping!&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jan 2024 20:15:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-code-every-minute/m-p/911043#M359251</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2024-01-09T20:15:30Z</dc:date>
    </item>
  </channel>
</rss>

