<?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 Loop to macro variables from character to numeric in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Do-Loop-to-macro-variables-from-character-to-numeric/m-p/540335#M7210</link>
    <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;I think it's because the values I feed into start, end, and incre variables are taken as character, rather than numeric&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;No.&amp;nbsp; Macro variables are ALWAYS character.&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The reason it doesn't work is because the iterative %DO loop only works for INTEGERS.&amp;nbsp; The implicit %EVAL() function call used in %DO&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;var= ... (and in %IF and %UNTIL and %WHILE)&amp;nbsp; can only do arithmetic on strings that look like integers.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If you want to make your own looping construct for floating point values then build it using %SYSEVALF().&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let weight=&amp;amp;start;
%do %while (%sysevalf(&amp;amp;weight &amp;lt;= &amp;amp;end));
   ....
   %let weight=%sysevalf(&amp;amp;weight + &amp;amp;incre);
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 05 Mar 2019 06:15:49 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-03-05T06:15:49Z</dc:date>
    <item>
      <title>Do Loop to macro variables from character to numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Do-Loop-to-macro-variables-from-character-to-numeric/m-p/540150#M7188</link>
      <description>&lt;P&gt;Hi SAS community,&lt;/P&gt;&lt;P&gt;I have a question that needs your wisdom.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to execute a macro and feed the macro with the following three variables: start, end, and incre.&lt;/P&gt;&lt;P&gt;All these three variables take two decimal points.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As shown below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;&lt;EM&gt;%macro loop(start=,end=,incre=);&lt;/EM&gt;&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;&lt;EM&gt;%local weight;&lt;/EM&gt;&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;&lt;EM&gt;%do weight = &amp;amp;start %to &amp;amp;end %by &amp;amp;incre;&lt;/EM&gt;&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;&lt;EM&gt;XXXXXXXXXXXXXX;&lt;/EM&gt;&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;&lt;EM&gt;XXXXXXXXXXXXXX (macro code);&lt;/EM&gt;&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;&lt;EM&gt;XXXXXXXXXXXXXX;&lt;/EM&gt;&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;&lt;EM&gt;%end;&lt;/EM&gt;&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;&lt;EM&gt;%mend;&lt;/EM&gt;&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;&lt;EM&gt;%macro(start= 0.5 ,end=0.99 ,incre=0.1 );&lt;/EM&gt;&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But, there is an error msg when I execute the code above, the error msg says the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;&lt;U&gt;A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:&lt;/U&gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;&lt;U&gt;.5&lt;/U&gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think it's because the values I feed into start, end, and incre variables are taken as character, rather than numeric&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What are the solutions to this problem?&lt;/P&gt;&lt;P&gt;Thank you all&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2019 18:53:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Do-Loop-to-macro-variables-from-character-to-numeric/m-p/540150#M7188</guid>
      <dc:creator>changxuosu</dc:creator>
      <dc:date>2019-03-04T18:53:42Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loop to macro variables from character to numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Do-Loop-to-macro-variables-from-character-to-numeric/m-p/540159#M7189</link>
      <description>&lt;P&gt;Macro %DO loops do not permit any characters, even decimal points.&amp;nbsp; You would have to switch to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%loop (start=50, end=99, incr=10)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then within the logic of the macro, divide these values by 100 as needed, to restore the proper logic.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2019 19:07:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Do-Loop-to-macro-variables-from-character-to-numeric/m-p/540159#M7189</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-03-04T19:07:04Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loop to macro variables from character to numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Do-Loop-to-macro-variables-from-character-to-numeric/m-p/540161#M7190</link>
      <description>&lt;P&gt;You might more completely describe what this code is supposed to do. Most of the time I when I see multiple variables with decimal values what is being done more appropriately belongs in a data step.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2019 19:10:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Do-Loop-to-macro-variables-from-character-to-numeric/m-p/540161#M7190</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-03-04T19:10:04Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loop to macro variables from character to numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Do-Loop-to-macro-variables-from-character-to-numeric/m-p/540214#M7199</link>
      <description>&lt;P&gt;Create your macro for a single instance, and use a data step loop with call execute().&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2019 20:55:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Do-Loop-to-macro-variables-from-character-to-numeric/m-p/540214#M7199</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-03-04T20:55:04Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loop to macro variables from character to numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Do-Loop-to-macro-variables-from-character-to-numeric/m-p/540335#M7210</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;I think it's because the values I feed into start, end, and incre variables are taken as character, rather than numeric&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;No.&amp;nbsp; Macro variables are ALWAYS character.&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The reason it doesn't work is because the iterative %DO loop only works for INTEGERS.&amp;nbsp; The implicit %EVAL() function call used in %DO&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;var= ... (and in %IF and %UNTIL and %WHILE)&amp;nbsp; can only do arithmetic on strings that look like integers.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If you want to make your own looping construct for floating point values then build it using %SYSEVALF().&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let weight=&amp;amp;start;
%do %while (%sysevalf(&amp;amp;weight &amp;lt;= &amp;amp;end));
   ....
   %let weight=%sysevalf(&amp;amp;weight + &amp;amp;incre);
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Mar 2019 06:15:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Do-Loop-to-macro-variables-from-character-to-numeric/m-p/540335#M7210</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-03-05T06:15:49Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loop to macro variables from character to numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Do-Loop-to-macro-variables-from-character-to-numeric/m-p/544052#M7795</link>
      <description>thanks a lot! I studied execute() it's a very useful tool. First time to use it. Thanks for introducing me to this useful tool!</description>
      <pubDate>Mon, 18 Mar 2019 17:35:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Do-Loop-to-macro-variables-from-character-to-numeric/m-p/544052#M7795</guid>
      <dc:creator>changxuosu</dc:creator>
      <dc:date>2019-03-18T17:35:21Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loop to macro variables from character to numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Do-Loop-to-macro-variables-from-character-to-numeric/m-p/544053#M7796</link>
      <description>thanks a lot Tom. It works perfect!</description>
      <pubDate>Mon, 18 Mar 2019 17:35:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Do-Loop-to-macro-variables-from-character-to-numeric/m-p/544053#M7796</guid>
      <dc:creator>changxuosu</dc:creator>
      <dc:date>2019-03-18T17:35:41Z</dc:date>
    </item>
  </channel>
</rss>

