<?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: Why is this simple a macro entering a infinite loop ? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Why-is-this-simple-a-macro-entering-a-infinite-loop/m-p/556892#M155178</link>
    <description>&lt;P&gt;Because the letter A is always smaller than the letter B in lexical ordering.&lt;/P&gt;</description>
    <pubDate>Tue, 07 May 2019 17:35:16 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-05-07T17:35:16Z</dc:date>
    <item>
      <title>Why is this simple a macro entering a infinite loop ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-is-this-simple-a-macro-entering-a-infinite-loop/m-p/556887#M155175</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope you are going well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone explain me why this is a infinite loop:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO TEST;
%LET A=3;
%LET B=6;
%IF &amp;amp;B &amp;gt;= &amp;amp;A %THEN %DO;

%DO %WHILE(A&amp;lt;B);
%PUT SOME TEXT OR INSTRUCTIONS;
%LET A=%EVAL(&amp;amp;A+1);
%END;

%END;
%MEND TEST;

%TEST;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And how to build a macro program to achieve the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;- Perform some instructions if B&amp;gt;A and increment A by 1.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;- Repeat this instruction until A=B&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2019 17:23:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-is-this-simple-a-macro-entering-a-infinite-loop/m-p/556887#M155175</guid>
      <dc:creator>Hugo_B</dc:creator>
      <dc:date>2019-05-07T17:23:41Z</dc:date>
    </item>
    <item>
      <title>Re: Why is this simple a macro entering a infinite loop ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-is-this-simple-a-macro-entering-a-infinite-loop/m-p/556888#M155176</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do while (&amp;amp;a&amp;lt;&amp;amp;b);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 May 2019 17:25:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-is-this-simple-a-macro-entering-a-infinite-loop/m-p/556888#M155176</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-05-07T17:25:05Z</dc:date>
    </item>
    <item>
      <title>Re: Why is this simple a macro entering a infinite loop ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-is-this-simple-a-macro-entering-a-infinite-loop/m-p/556889#M155177</link>
      <description>&lt;P&gt;You forgot &amp;amp; signs in your&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;&lt;SPAN class="token macrostatement"&gt;%DO&lt;/SPAN&gt; &lt;SPAN class="token macrostatement"&gt;%WHILE&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;A&lt;SPAN class="token operator"&gt;&amp;lt;&lt;/SPAN&gt;B&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/LI-CODE&gt;
&lt;P&gt;If you add the &amp;amp;, looks like it's doing what you want:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO TEST;
%local A B ;
%LET A=3;
%LET B=6;
%IF &amp;amp;B &amp;gt;= &amp;amp;A %THEN %DO;

%DO %WHILE(&amp;amp;A&amp;lt;&amp;amp;B);
%PUT &amp;amp;=A &amp;amp;=B SOME TEXT OR INSTRUCTIONS;
%LET A=%EVAL(&amp;amp;A+1);
%END;

%END;
%MEND TEST;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2019 17:26:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-is-this-simple-a-macro-entering-a-infinite-loop/m-p/556889#M155177</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2019-05-07T17:26:37Z</dc:date>
    </item>
    <item>
      <title>Re: Why is this simple a macro entering a infinite loop ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-is-this-simple-a-macro-entering-a-infinite-loop/m-p/556892#M155178</link>
      <description>&lt;P&gt;Because the letter A is always smaller than the letter B in lexical ordering.&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2019 17:35:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-is-this-simple-a-macro-entering-a-infinite-loop/m-p/556892#M155178</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-05-07T17:35:16Z</dc:date>
    </item>
    <item>
      <title>Re: Why is this simple a macro entering a infinite loop ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-is-this-simple-a-macro-entering-a-infinite-loop/m-p/556893#M155179</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/272343"&gt;@Hugo_B&lt;/a&gt;&amp;nbsp; &amp;nbsp;While others have answered or given you the needed correction.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Can someone explain me why this is a infinite loop:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Since we know macro language processes text, it's clear in an ascii or ebcidic collating sequence A is less than B. Your do while expression evaluates at the top of the loop which always is true. That's what is the cause of your infinite loop. In your case, you have two letters and not two macro variable references. This is a great teaser to many who won't take notice.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Look at this example--&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro t;
%if b&amp;lt;a %then %put true;
%else %put false;
%mend t;
%t&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 May 2019 17:35:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-is-this-simple-a-macro-entering-a-infinite-loop/m-p/556893#M155179</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-05-07T17:35:25Z</dc:date>
    </item>
    <item>
      <title>Re: Why is this simple a macro entering a infinite loop ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-is-this-simple-a-macro-entering-a-infinite-loop/m-p/557070#M155251</link>
      <description>Thank you, I didn't even know that it was possible two compare letters or strings.</description>
      <pubDate>Wed, 08 May 2019 12:02:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-is-this-simple-a-macro-entering-a-infinite-loop/m-p/557070#M155251</guid>
      <dc:creator>Hugo_B</dc:creator>
      <dc:date>2019-05-08T12:02:02Z</dc:date>
    </item>
    <item>
      <title>Re: Why is this simple a macro entering a infinite loop ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-is-this-simple-a-macro-entering-a-infinite-loop/m-p/557219#M155304</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/272343"&gt;@Hugo_B&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thank you, I didn't even know that it was possible two compare letters or strings.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Just don't expect results to always be as expected when numerals in a&amp;nbsp;string (character) value&amp;nbsp;are involved and Upper case come before Lower case. '1000' is "less than" '9' because character comparisons use character by character comparisons. Since the first 1 in '1000' is before '9' then it is "less".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also 'a' is "greater than" 'Z'&amp;nbsp; (ALL lower case come after all uppercase letters)&lt;/P&gt;
&lt;PRE&gt;data _null_;
 if 'a' &amp;lt; 'Z' then put 'a is less than Z';
 else if 'a' &amp;gt; 'Z' then put 'a is greater than Z';
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 May 2019 18:05:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-is-this-simple-a-macro-entering-a-infinite-loop/m-p/557219#M155304</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-05-08T18:05:20Z</dc:date>
    </item>
  </channel>
</rss>

