<?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: %do %until vs %do %while in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/do-until-vs-do-while/m-p/253107#M48129</link>
    <description>&lt;P&gt;"&lt;SPAN&gt;Can %do %until be replaced by %do %while in all conditions?"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;No. but&amp;nbsp;%do %while could replace&amp;nbsp;%do %until.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;There is very important different thing between them is&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;%do %until will iterative at least once , but&amp;nbsp; %do %while could iterative ZERO time.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 29 Feb 2016 01:37:57 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2016-02-29T01:37:57Z</dc:date>
    <item>
      <title>%do %until vs %do %while</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-until-vs-do-while/m-p/253054#M48111</link>
      <description>&lt;P&gt;I know %do %until checks the loop exit condition at the bottop of loop while %do %while checks at the top of loop. Can %do %until be replaced by %do %while in all conditions? Are there any situations when only %do %until or %do %while can be used?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro m;
	%local i;
	%let i=0;

	%do %until (&amp;amp;i ge 3); 

		data dat&amp;amp;i;
			set sashelp.class;
		run;

		%let i=%eval(&amp;amp;i+1);
	%end;
%mend m;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Feb 2016 00:11:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-until-vs-do-while/m-p/253054#M48111</guid>
      <dc:creator>SAS_inquisitive</dc:creator>
      <dc:date>2016-02-29T00:11:37Z</dc:date>
    </item>
    <item>
      <title>Re: %do %until vs %do %while</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-until-vs-do-while/m-p/253061#M48112</link>
      <description>&lt;P&gt;I'm not sure, but probably. But either one can be awkward in different situations - that's why you got both to chose from.&lt;/P&gt;
&lt;P&gt;You'ra asking for an absolute answer. Why? Do you have a specific problem?&lt;/P&gt;</description>
      <pubDate>Sun, 28 Feb 2016 20:24:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-until-vs-do-while/m-p/253061#M48112</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-02-28T20:24:22Z</dc:date>
    </item>
    <item>
      <title>Re: %do %until vs %do %while</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-until-vs-do-while/m-p/253105#M48122</link>
      <description>&lt;P&gt;One situation where %DO %WHILE can work and %DO %UNTIL cannot work&amp;nbsp;is when you have a condition for which you want the inside of the loop to never execute.&amp;nbsp; On the first iteration of the loop if a %DO %WHILE condition is false, the code inside the loop will not be excecuted.&amp;nbsp; But on the first iteration of a %DO %UNTIL loop if the condition is true, the inside of the loop will be executed.&amp;nbsp; Conversely, if you want to force the inside of the loop to ALWAYS execute at least once, then you would want %DO %UNTIL, not %DO WHILE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As an example, consider the below macros, which print a list of datasets with a %DO %WHILE loop or a %DO %UNTIL loop:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro PrintListWhile(datalist=,obs=5);
  %local i data;
  %let i=1;
  %let data=%scan(&amp;amp;datalist,&amp;amp;i,%str( ));
  %do %while(%superq(data) ne %str());
    proc print data=&amp;amp;data(obs=&amp;amp;obs);
    run;
    %let i=%eval(&amp;amp;i+1);
    %let data=%scan(&amp;amp;datalist,&amp;amp;i,%str( ));
  %end;
%mend;

%macro PrintListUntil(datalist=,obs=5);
  %local i data;
  %let i=1;
  %let data=%scan(&amp;amp;datalist,&amp;amp;i,%str( ));
  %do %until(%superq(data) eq %str());
    proc print data=&amp;amp;data(obs=&amp;amp;obs);
    run;
    %let i=%eval(&amp;amp;i+1);
    %let data=%scan(&amp;amp;datalist,&amp;amp;i,%str( ));
  %end;
%mend;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Both macros will give you the same result when you pass it a list of datasets:&lt;/P&gt;
&lt;PRE&gt;%PrintListWhile(datalist=sashelp.class sashelp.shoes sashelp.prdsale)
%PrintListUntil(datalist=sashelp.class sashelp.shoes sashelp.prdsale)
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if you pass it an empty list:&lt;/P&gt;
&lt;PRE&gt;%PrintListWhile(datalist=)
%PrintListUntil(datalist=)&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%PrintListWhile will work.&amp;nbsp; It will not generate any PROC PRINT code.&lt;/P&gt;
&lt;P&gt;%PrintListUntil will error, because it generates an invalid PROC PRINT step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;231  %PrintListUntil(datalist=)
NOTE: Line generated by the invoked macro "PRINTLISTUNTIL".
1      proc print data=&amp;amp;data(obs=&amp;amp;obs);     run;
                            -
                            22
                            200
MPRINT(PRINTLISTUNTIL):   proc print data=(obs=5) NAME;
ERROR: File WORK.NAME.DATA does not exist.
MPRINT(PRINTLISTUNTIL):   run;

ERROR 22-322: Expecting a name.

ERROR 200-322: The symbol is not recognized and will be ignored.
&lt;/PRE&gt;</description>
      <pubDate>Mon, 29 Feb 2016 01:27:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-until-vs-do-while/m-p/253105#M48122</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2016-02-29T01:27:25Z</dc:date>
    </item>
    <item>
      <title>Re: %do %until vs %do %while</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-until-vs-do-while/m-p/253107#M48129</link>
      <description>&lt;P&gt;"&lt;SPAN&gt;Can %do %until be replaced by %do %while in all conditions?"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;No. but&amp;nbsp;%do %while could replace&amp;nbsp;%do %until.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;There is very important different thing between them is&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;%do %until will iterative at least once , but&amp;nbsp; %do %while could iterative ZERO time.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Feb 2016 01:37:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-until-vs-do-while/m-p/253107#M48129</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-02-29T01:37:57Z</dc:date>
    </item>
  </channel>
</rss>

