<?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: the %WHILE and %UNTIL specifications cannot be added to the increments in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/the-WHILE-and-UNTIL-specifications-cannot-be-added-to-the/m-p/899486#M355536</link>
    <description>&lt;P&gt;In normal SAS data step code, you could do something like this, which simultaneously uses both a do index range and an until condition as limits on the number of do loop iterations:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  do i=1 to 90 until (rannum&amp;gt;0.9);
    rannum=ranuni(4150913);
    put i= rannum=;
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The loop will stop once i is incremented beyond 90, or rannum exceeds 0.9, whichever happens first.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if you write the intuitively analogous macro code, you get the error messages in the log below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;667  %macro t;
668    %do i=1 %to 90 %until (&amp;amp;rannum &amp;gt; 0.9);
669      %let rannum=%sysfunc(ranuni(4150913));
670    %end;
671  %mend t;
672  %t ;
ERROR: Improper use of macro reserved word until.
WARNING: Apparent symbolic reference RANNUM not resolved.
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric
       operand is required. The condition was: 90 %until (&amp;amp;rannum &amp;gt; 0.9)
ERROR: The %TO value of the %DO I loop is invalid.
ERROR: The macro T will stop executing.
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Instead, you have to include both the index limit and the until condition into a compound until condition:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro t;
  %let i=0;
  %do %until (&amp;amp;rannum &amp;gt; 0.9 OR &amp;amp;i=90);
    %let i=%eval(&amp;amp;i+1);
    %let rannum=%sysfunc(ranuni(4150913));
    %put &amp;amp;=i &amp;amp;=rannum;
  %end;
%mend t;
%t ;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 21 Oct 2023 01:07:37 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2023-10-21T01:07:37Z</dc:date>
    <item>
      <title>the %WHILE and %UNTIL specifications cannot be added to the increments</title>
      <link>https://communities.sas.com/t5/SAS-Programming/the-WHILE-and-UNTIL-specifications-cannot-be-added-to-the/m-p/899484#M355534</link>
      <description>&lt;P&gt;Hello&lt;BR /&gt;I was trying to learn about Macros in SAS. While reading the paper "&lt;STRONG&gt;Five Ways to Create Macro Variables: A Short Introduction to the Macro Language by Arthur L. Carpenter,&lt;/STRONG&gt;&amp;nbsp; I got stuck at the statement in the section on I&lt;STRONG&gt;terative % DO&lt;/STRONG&gt; &lt;STRONG&gt;loops &lt;/STRONG&gt;page 4.&lt;/P&gt;
&lt;PRE&gt;the %WHILE and %UNTIL specifications cannot be added to the increments&lt;/PRE&gt;
&lt;P&gt;The author is an expert and there must be great significance in the above statement. I am unable to comprehend it.&lt;BR /&gt;Can anybody please help me understand this?&lt;BR /&gt;It is my understanding that %Do %WHILE and %DO %Until constructs can be used in macros.&lt;BR /&gt;Thanks in anticipation.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2023 23:26:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/the-WHILE-and-UNTIL-specifications-cannot-be-added-to-the/m-p/899484#M355534</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2023-10-20T23:26:26Z</dc:date>
    </item>
    <item>
      <title>Re: the %WHILE and %UNTIL specifications cannot be added to the increments</title>
      <link>https://communities.sas.com/t5/SAS-Programming/the-WHILE-and-UNTIL-specifications-cannot-be-added-to-the/m-p/899485#M355535</link>
      <description>&lt;P&gt;The SAS datastep allows for constructs as below.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  do i=1 to 99 until(var&amp;gt;99);
    var=i*i;
  end;
  put i= var=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The same is not possible with SAS macro language. Below code will return a syntax error.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro demo1();
  %local var;
  %do i=1 %to 99 %until(&amp;amp;var&amp;gt;99);
    %let var= %eval(&amp;amp;i*&amp;amp;i);
  %end;
  %put &amp;amp;=i &amp;amp;=var;
%mend;
%demo1();&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To express such logic on SAS macro level you need to implement differently - for example as below.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro demo2();
  %local i;
  %do %until(&amp;amp;var&amp;gt;99);
    %let i=%eval(&amp;amp;i+1);
    %let var= %eval(&amp;amp;i*&amp;amp;i);
  %end;
  %put &amp;amp;=i &amp;amp;=var;
%mend;
%demo2();&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 21 Oct 2023 01:09:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/the-WHILE-and-UNTIL-specifications-cannot-be-added-to-the/m-p/899485#M355535</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-10-21T01:09:05Z</dc:date>
    </item>
    <item>
      <title>Re: the %WHILE and %UNTIL specifications cannot be added to the increments</title>
      <link>https://communities.sas.com/t5/SAS-Programming/the-WHILE-and-UNTIL-specifications-cannot-be-added-to-the/m-p/899486#M355536</link>
      <description>&lt;P&gt;In normal SAS data step code, you could do something like this, which simultaneously uses both a do index range and an until condition as limits on the number of do loop iterations:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  do i=1 to 90 until (rannum&amp;gt;0.9);
    rannum=ranuni(4150913);
    put i= rannum=;
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The loop will stop once i is incremented beyond 90, or rannum exceeds 0.9, whichever happens first.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if you write the intuitively analogous macro code, you get the error messages in the log below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;667  %macro t;
668    %do i=1 %to 90 %until (&amp;amp;rannum &amp;gt; 0.9);
669      %let rannum=%sysfunc(ranuni(4150913));
670    %end;
671  %mend t;
672  %t ;
ERROR: Improper use of macro reserved word until.
WARNING: Apparent symbolic reference RANNUM not resolved.
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric
       operand is required. The condition was: 90 %until (&amp;amp;rannum &amp;gt; 0.9)
ERROR: The %TO value of the %DO I loop is invalid.
ERROR: The macro T will stop executing.
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Instead, you have to include both the index limit and the until condition into a compound until condition:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro t;
  %let i=0;
  %do %until (&amp;amp;rannum &amp;gt; 0.9 OR &amp;amp;i=90);
    %let i=%eval(&amp;amp;i+1);
    %let rannum=%sysfunc(ranuni(4150913));
    %put &amp;amp;=i &amp;amp;=rannum;
  %end;
%mend t;
%t ;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 21 Oct 2023 01:07:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/the-WHILE-and-UNTIL-specifications-cannot-be-added-to-the/m-p/899486#M355536</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-10-21T01:07:37Z</dc:date>
    </item>
    <item>
      <title>Re: the %WHILE and %UNTIL specifications cannot be added to the increments</title>
      <link>https://communities.sas.com/t5/SAS-Programming/the-WHILE-and-UNTIL-specifications-cannot-be-added-to-the/m-p/899487#M355537</link>
      <description>&lt;P&gt;Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp; and &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt; for helping me understand it.&lt;/P&gt;</description>
      <pubDate>Sat, 21 Oct 2023 01:15:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/the-WHILE-and-UNTIL-specifications-cannot-be-added-to-the/m-p/899487#M355537</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2023-10-21T01:15:55Z</dc:date>
    </item>
  </channel>
</rss>

