<?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: convert macro value to numeric in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/convert-macro-value-to-numeric/m-p/882681#M348731</link>
    <description>&lt;P&gt;The %EVAL function cannot be applied to a DATA step variable such as yr17.&amp;nbsp; Just remove it (and the related parentheses).&lt;/P&gt;</description>
    <pubDate>Tue, 27 Jun 2023 18:59:07 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2023-06-27T18:59:07Z</dc:date>
    <item>
      <title>convert macro value to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-macro-value-to-numeric/m-p/882676#M348730</link>
      <description>&lt;P&gt;Can anyone suggest a fix to this code?&amp;nbsp; I'm trying to divide the value yr17 by the macro variable value &amp;amp;yr17&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;27 proc sql noprint;&lt;BR /&gt;28 select yr17 into :yr17&lt;BR /&gt;29 from T10_1&lt;BR /&gt;30 where Group=1;&lt;BR /&gt;31 quit;&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;cpu time 0.00 seconds&lt;/P&gt;&lt;P&gt;32&lt;BR /&gt;33 options symbolgen;&lt;BR /&gt;34 proc sql;&lt;BR /&gt;35 select put(Group,Group_num.) as Group, Value, yr17, %eval(yr17/&amp;amp;yr17) as Pct17&lt;BR /&gt;SYMBOLGEN: Macro variable YR17 resolves to 4,618&lt;BR /&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:&lt;BR /&gt;yr17/ 4,618&lt;BR /&gt;35 select put(Group,Group_num.) as Group, Value, yr17, %eval(yr17/&amp;amp;yr17) as Pct17&lt;BR /&gt;_____&lt;BR /&gt;22&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, *, **, +, ',', -, '.', /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;=, ?, AND, AS,&lt;BR /&gt;CONTAINS, EQ, EQT, GE, GET, GT, GTT, LE, LET, LIKE, LT, LTT, NE, NET, OR, ^=, |, ||, ~=.&lt;/P&gt;&lt;P&gt;2 The SAS System 14:03 Tuesday, June 27, 2023&lt;/P&gt;&lt;P&gt;36 from T10_1&lt;BR /&gt;37 where Group=2;&lt;BR /&gt;NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.&lt;BR /&gt;38 quit;&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;cpu time 0.00 seconds&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jun 2023 18:48:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-macro-value-to-numeric/m-p/882676#M348730</guid>
      <dc:creator>Batman</dc:creator>
      <dc:date>2023-06-27T18:48:33Z</dc:date>
    </item>
    <item>
      <title>Re: convert macro value to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-macro-value-to-numeric/m-p/882681#M348731</link>
      <description>&lt;P&gt;The %EVAL function cannot be applied to a DATA step variable such as yr17.&amp;nbsp; Just remove it (and the related parentheses).&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jun 2023 18:59:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-macro-value-to-numeric/m-p/882681#M348731</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2023-06-27T18:59:07Z</dc:date>
    </item>
    <item>
      <title>Re: convert macro value to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-macro-value-to-numeric/m-p/882682#M348732</link>
      <description>&lt;P&gt;First, just to be technically correct, macro variables are always text. There is no such thing as a numeric macro variable. (They may look like numbers to humans, but they are text).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Next, the macro processor just replaces macro variables with their value, and the result MUST BE valid legal working SAS code. So if your macro variable has value&amp;nbsp;&lt;SPAN&gt;4,618, when this replaces the macro variable, you get &lt;FONT face="courier new,courier"&gt;yr17/4,618&lt;/FONT&gt; which is NOT legal valid working SAS code. Can you see why this doesn't work??? It has nothing to do with macro variables.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;So, the problem is that the value of variable YR17 in data set T10_1 is not a valid number, it is a character string '4,618'. So that's where you need to do the conversion to a character string without commas (or other non-digits); or create a numeric variable with value 4618 and then make that the value of the macro variable &amp;amp;YR17. Then you get the SAS code using the numeric version of YR17 which I shall call YR17n which reads&amp;nbsp;&lt;FONT face="courier new,courier"&gt;yr17n/4618&lt;/FONT&gt; and everyone is happy.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Which brings us to the big question ... why use a macro variable here anyway? Since yr17 is obviously a character variable, this should work without macro variables.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; proc sql;
    select a.Group format=Group_num., a.Value, a.yr17,
          input(a.yr17,comma8.0)/input(b.yr17,comma8.0) as Pct17
    from T10_1(where=(Group=2)) as a left join t10_1(where=(group=1)) as b;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jun 2023 19:12:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-macro-value-to-numeric/m-p/882682#M348732</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-06-27T19:12:07Z</dc:date>
    </item>
  </channel>
</rss>

