<?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: Help with loop needed -- code suggestions and examples needed in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Help-with-loop-needed-code-suggestions-and-examples-needed/m-p/508261#M136478</link>
    <description>Sleep function provides a controlled delay until retesting to see if the filter returns a non-empty set.&lt;BR /&gt;I don't see how a data step could use the DO UNTIL()  control as (iirc) a  data step stops when the WHERE executes  and returns an empty set. &lt;BR /&gt;</description>
    <pubDate>Mon, 29 Oct 2018 08:15:49 GMT</pubDate>
    <dc:creator>Peter_C</dc:creator>
    <dc:date>2018-10-29T08:15:49Z</dc:date>
    <item>
      <title>Help with loop needed -- code suggestions and examples needed</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-loop-needed-code-suggestions-and-examples-needed/m-p/508252#M136475</link>
      <description>&lt;P&gt;I am attempting to write some code, possibly a do until loop,&amp;nbsp;that will keep running the following proc sql block until all of the conditions in the where clause are met. Once the conditions are met, I need to run an X command. What is the best way to code this? Please provide sample code. Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;

create table trigger as

select Name, TDate, Status

from TDB.TTABLE

where Name="Load" and TDate=today() and Status="Ready";

quit;

 

x 'ksh /path/to/file/kshell.ksh'&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 29 Oct 2018 06:42:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-loop-needed-code-suggestions-and-examples-needed/m-p/508252#M136475</guid>
      <dc:creator>ijmoorejr</dc:creator>
      <dc:date>2018-10-29T06:42:09Z</dc:date>
    </item>
    <item>
      <title>Re: Help with loop needed -- code suggestions and examples needed</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-loop-needed-code-suggestions-and-examples-needed/m-p/508261#M136478</link>
      <description>Sleep function provides a controlled delay until retesting to see if the filter returns a non-empty set.&lt;BR /&gt;I don't see how a data step could use the DO UNTIL()  control as (iirc) a  data step stops when the WHERE executes  and returns an empty set. &lt;BR /&gt;</description>
      <pubDate>Mon, 29 Oct 2018 08:15:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-loop-needed-code-suggestions-and-examples-needed/m-p/508261#M136478</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2018-10-29T08:15:49Z</dc:date>
    </item>
    <item>
      <title>Re: Help with loop needed -- code suggestions and examples needed</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-loop-needed-code-suggestions-and-examples-needed/m-p/508265#M136481</link>
      <description>&lt;P&gt;Use scheduling software, its what it is made for and will be better than anything you will likely write.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Oct 2018 08:34:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-loop-needed-code-suggestions-and-examples-needed/m-p/508265#M136481</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-10-29T08:34:58Z</dc:date>
    </item>
    <item>
      <title>Re: Help with loop needed -- code suggestions and examples needed</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-loop-needed-code-suggestions-and-examples-needed/m-p/508268#M136484</link>
      <description>&lt;P&gt;I agree with RW9 that scheduling software may be the best solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I did create an example for you to try, but tested on Windows. I would expect the same behaviour on Unix.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro waitfor_new_data(Waittime=1, Maxtries=5);
  %let Try=1;
  %let trigger=0;
  %* Loop until either new data is ready or max number of tries reached.;
  %do %until(&amp;amp;trigger = 1 or &amp;amp;Try &amp;gt; &amp;amp;Maxtries );
    proc sql noprint;
      select 
        count(*) &amp;gt; 0 format=8.
        into : trigger trimmed
      from TDB.TTABLE
      where Name="Load" and TDate=today() and Status="Ready";
    quit;
    %let Try=%eval(&amp;amp;Try+1);
    %if &amp;amp;trigger = 0 and &amp;amp;Try &amp;lt;= &amp;amp;Maxtries %then %do;
      %put NOTE: Waiting for &amp;amp;Waittime seconds...;
      %let rc=%sysfunc(sleep(&amp;amp;Waittime,1));
    %end;
  %end;

  %if &amp;amp;trigger = 0 %then %do;
    %put NOTE: Max tries executed and no new data found, execution stopped.;
  %end;
  %else %do;
    %put NOTE: New data found, executing script.;
/*x 'ksh /path/to/file/kshell.ksh';*/
  %end;
%mend;

/* Create a test table */
libname tdb "C:\Temp";
data tdb.TTABLE;
  Name = 'Load';
  TDate = today()-1;
  Status = 'Ready' ;
run;
%waitfor_new_data(Waittime=2, Maxtries=5);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 29 Oct 2018 08:46:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-loop-needed-code-suggestions-and-examples-needed/m-p/508268#M136484</guid>
      <dc:creator>MichaelLarsen</dc:creator>
      <dc:date>2018-10-29T08:46:41Z</dc:date>
    </item>
    <item>
      <title>Re: Help with loop needed -- code suggestions and examples needed</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-loop-needed-code-suggestions-and-examples-needed/m-p/508270#M136485</link>
      <description>For the example to find new data you should remove the -1 in the data step that generates the test table.</description>
      <pubDate>Mon, 29 Oct 2018 08:48:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-loop-needed-code-suggestions-and-examples-needed/m-p/508270#M136485</guid>
      <dc:creator>MichaelLarsen</dc:creator>
      <dc:date>2018-10-29T08:48:15Z</dc:date>
    </item>
  </channel>
</rss>

