<?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: How to schedule to run SAS code every minute at mm:05 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-schedule-to-run-SAS-code-every-minute-at-mm-05/m-p/841218#M332610</link>
    <description>&lt;P&gt;As Paige said, scheduling via the OS (task scheduler on Windows, crontab on linux) is usually the best approach.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you mention the SLEEP() function, note that SAS on Windows has a WAKEUP() function which allows you to wake at a certain time.&amp;nbsp; If you wanted to say "wake me at 5 seconds past the next minute," you could do&amp;nbsp; something ugly like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Check the time to wakeup, 5 seconds after the start of the next minute ;
%put %sysfunc(putn(%eval(%sysfunc(intnx(minute,"%sysfunc( time(), time )"t,1))+5),time.)) ;

*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));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So you would put that inside an infinite loop which runs your code, and then sleeps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I only mention that because you mentioned the SLEEP function.&amp;nbsp; Using&amp;nbsp; OS scheduling tools is much much better.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 27 Oct 2022 20:00:05 GMT</pubDate>
    <dc:creator>Quentin</dc:creator>
    <dc:date>2022-10-27T20:00:05Z</dc:date>
    <item>
      <title>How to schedule to run SAS code every minute at mm:05</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-schedule-to-run-SAS-code-every-minute-at-mm-05/m-p/841176#M332586</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;I would like to run my SAS code using (%include command) every minute at, say, 5th second.&lt;/P&gt;
&lt;P&gt;(The sleep option seems not working for me since I don't know how long the code runs)&lt;/P&gt;
&lt;P&gt;Can you please help?&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Include "E:\SAS code.sas";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Oct 2022 15:47:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-schedule-to-run-SAS-code-every-minute-at-mm-05/m-p/841176#M332586</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2022-10-27T15:47:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to schedule to run SAS code every minute at mm:05</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-schedule-to-run-SAS-code-every-minute-at-mm-05/m-p/841184#M332590</link>
      <description>&lt;P&gt;Scheduling of tasks is usually done in the operating system. For example, Windows has an applicatoin called Task Scheduler that can cause your SAS code to be run at any time or at any frequency.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Oct 2022 16:42:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-schedule-to-run-SAS-code-every-minute-at-mm-05/m-p/841184#M332590</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-10-27T16:42:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to schedule to run SAS code every minute at mm:05</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-schedule-to-run-SAS-code-every-minute-at-mm-05/m-p/841217#M332609</link>
      <description>&lt;P&gt;Running a batch program every minute is going to produce 60 SAS logs per hour and 1,440 per day. A looping program would be better but you need to check how long each run takes. Why does it need to be run so often?&lt;/P&gt;</description>
      <pubDate>Thu, 27 Oct 2022 19:57:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-schedule-to-run-SAS-code-every-minute-at-mm-05/m-p/841217#M332609</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-10-27T19:57:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to schedule to run SAS code every minute at mm:05</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-schedule-to-run-SAS-code-every-minute-at-mm-05/m-p/841218#M332610</link>
      <description>&lt;P&gt;As Paige said, scheduling via the OS (task scheduler on Windows, crontab on linux) is usually the best approach.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you mention the SLEEP() function, note that SAS on Windows has a WAKEUP() function which allows you to wake at a certain time.&amp;nbsp; If you wanted to say "wake me at 5 seconds past the next minute," you could do&amp;nbsp; something ugly like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Check the time to wakeup, 5 seconds after the start of the next minute ;
%put %sysfunc(putn(%eval(%sysfunc(intnx(minute,"%sysfunc( time(), time )"t,1))+5),time.)) ;

*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));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So you would put that inside an infinite loop which runs your code, and then sleeps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I only mention that because you mentioned the SLEEP function.&amp;nbsp; Using&amp;nbsp; OS scheduling tools is much much better.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Oct 2022 20:00:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-schedule-to-run-SAS-code-every-minute-at-mm-05/m-p/841218#M332610</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-10-27T20:00:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to schedule to run SAS code every minute at mm:05</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-schedule-to-run-SAS-code-every-minute-at-mm-05/m-p/841222#M332611</link>
      <description>&lt;P&gt;The simple scheduling daemon cron, used on UNIX systems, can break down to minutes. If the 5 seconds are crucial, run the SLEEP function as first action of your code. But keep in mind that initiating a SAS session already takes time (where I used to work, pre-assigning all metadata bound libraries took about half a minute).&lt;/P&gt;</description>
      <pubDate>Thu, 27 Oct 2022 20:29:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-schedule-to-run-SAS-code-every-minute-at-mm-05/m-p/841222#M332611</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-10-27T20:29:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to schedule to run SAS code every minute at mm:05</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-schedule-to-run-SAS-code-every-minute-at-mm-05/m-p/841224#M332612</link>
      <description>I am thinking about a macro that runs the code. Keep track of the Time it ends (time-end). Then calculate the gap time betwwen time-end and the next minutes and 5 second. &lt;BR /&gt;This gap time will be put into sleep &lt;BR /&gt;This way, Sas will resume and run the next round right at mm:05 ( or around that time).&lt;BR /&gt;I might break my question into piece if this above approach works.&lt;BR /&gt;Thanks.&lt;BR /&gt;Hhc</description>
      <pubDate>Thu, 27 Oct 2022 20:46:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-schedule-to-run-SAS-code-every-minute-at-mm-05/m-p/841224#M332612</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2022-10-27T20:46:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to schedule to run SAS code every minute at mm:05</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-schedule-to-run-SAS-code-every-minute-at-mm-05/m-p/841226#M332614</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/49486"&gt;@hhchenfx&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I am thinking about a macro that runs the code. Keep track of the Time it ends (time-end). Then calculate the gap time betwwen time-end and the next minutes and 5 second. &lt;BR /&gt;This gap time will be put into sleep &lt;BR /&gt;This way, Sas will resume and run the next round right at mm:05 ( or around that time).&lt;BR /&gt;I might break my question into piece if this above approach works.&lt;BR /&gt;Thanks.&lt;BR /&gt;Hhc&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That's how I was thinking you could use the WAKEUP function example I posted. But instead of calculating the gap, you just tell SAS to wake up at 5 seconds after the start of the next minute. Something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro doeveryminute() ;

  %*beware the infinite loop ;
  %do %while (1) ;

    *do something ;
    title1 "Current Time: %sysfunc( time(), time )" ;
    proc print data=sashelp.class ;
    run ;
    title1 ;

    %*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 ;

%doeveryminute()&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Oct 2022 21:13:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-schedule-to-run-SAS-code-every-minute-at-mm-05/m-p/841226#M332614</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-10-27T21:13:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to schedule to run SAS code every minute at mm:05</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-schedule-to-run-SAS-code-every-minute-at-mm-05/m-p/841243#M332624</link>
      <description>&lt;P&gt;Commercial job schedulers (Autosys, Control M) have provision assign both time and dependency.&lt;BR /&gt;You can explore if that works in your case.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Oct 2022 00:06:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-schedule-to-run-SAS-code-every-minute-at-mm-05/m-p/841243#M332624</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2022-10-28T00:06:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to schedule to run SAS code every minute at mm:05</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-schedule-to-run-SAS-code-every-minute-at-mm-05/m-p/841246#M332625</link>
      <description>&lt;P&gt;Yeah!&lt;/P&gt;
&lt;P&gt;Thanks a lot.&lt;/P&gt;
&lt;P&gt;It works perfectly.&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;</description>
      <pubDate>Fri, 28 Oct 2022 01:31:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-schedule-to-run-SAS-code-every-minute-at-mm-05/m-p/841246#M332625</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2022-10-28T01:31:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to schedule to run SAS code every minute at mm:05</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-schedule-to-run-SAS-code-every-minute-at-mm-05/m-p/841500#M332747</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro doeveryminute() ;

  %do %while (   %sysevalf(%sysfunc(time())&amp;lt;'21:56:08't,boolean)  ) ;

    *do something ;
	 data _null_;
	    dt=today(); format dt yymmdd10.;
		curr_datetime=datetime(); format curr_datetime datetime20.; 

	    put dt ;
		put curr_datetime;
	run;

    %*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 ;

%doeveryminute()&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 30 Oct 2022 01:58:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-schedule-to-run-SAS-code-every-minute-at-mm-05/m-p/841500#M332747</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2022-10-30T01:58:48Z</dc:date>
    </item>
  </channel>
</rss>

