<?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: ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/ERROR-A-character-operand-was-found-in-the-EVAL-function-or-IF/m-p/174948#M33607</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I’ll try to add an explanation in case readers are wondering what’s going on in the solution suggested by CTorres. A %DO loop can be used to generate a block of SAS code repeatedly with different index values. However, since %DO is a macro statement, any variables in it would have to be macro variables. There are various ways to create macro variables, and the CALL SYMPUTX routine is a good approach if you want to create a macro variable from a a value in a data step. Then, once the macro variable exists, a macro variable reference has to begin with an ampersand — that’s what marks it as a macro variable. As originally presented, the %DO statement is looking at the text “numDim” in the %DO statement, rather than a variable. The %DO statement uses the %EVAL function to get the numeric value of its %TO argument, and this is why the error message refers to the %EVAL function.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 08 Jan 2015 16:38:56 GMT</pubDate>
    <dc:creator>RickAster</dc:creator>
    <dc:date>2015-01-08T16:38:56Z</dc:date>
    <item>
      <title>ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-A-character-operand-was-found-in-the-EVAL-function-or-IF/m-p/174945#M33604</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am getting this error on the following code. Even though numDim is clearly a numeric value. When I replace "%do i = 1 %to numDim" with "%do i = 1 %to 5" it works. Any ideas on why this error is occuring and how to fix it?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ERROR: A character operand was found in the %EVAL function or %IF condition&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where a numeric operand is required. The condition was: numDim&lt;/P&gt;&lt;P&gt;ERROR: The %TO value of the %DO I loop is invalid.&lt;/P&gt;&lt;P&gt;ERROR: The macro CREATEDIMS will stop executing.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; input idno 1-2 l_name $ 5-9 diag $ 12-30;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; cards;&lt;BR /&gt;10&amp;nbsp; Smith&amp;nbsp; 123:199:256:277:600&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test_1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; length numDim 8.;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; set test;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; numDim=(countc(diag, ':')+1);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro createDims();&lt;BR /&gt;&amp;nbsp;&amp;nbsp; data test_2;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set test_1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do i = 1 %to numDim;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Variable_a&amp;amp;i = scan(diag, &amp;amp;i, ':');&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; diag_code=Variable_a&amp;amp;i.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; drop diag Variable_a&amp;amp;i;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; run;&lt;BR /&gt;%mend createDims;&lt;BR /&gt;%createDims()&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jan 2015 16:09:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-A-character-operand-was-found-in-the-EVAL-function-or-IF/m-p/174945#M33604</guid>
      <dc:creator>robby_beum</dc:creator>
      <dc:date>2015-01-08T16:09:51Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-A-character-operand-was-found-in-the-EVAL-function-or-IF/m-p/174946#M33605</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; input idno 1-2 l_name $ 5-9 diag $ 12-30;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; cards;&lt;BR /&gt;10&amp;nbsp; Smith&amp;nbsp; 123:199:256:277:600&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test_1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; length numDim 8.;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; set test;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; numDim=(countc(diag, ':')+1);&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; call symputx('numDim',numDim);&lt;/STRONG&gt;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro createDims();&lt;BR /&gt;&amp;nbsp;&amp;nbsp; data test_2;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set test_1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do i = 1 %to &lt;STRONG&gt;&amp;amp;numDim;&lt;/STRONG&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Variable_a&amp;amp;i = scan(diag, &amp;amp;i, ':');&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; diag_code=Variable_a&amp;amp;i.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; drop diag Variable_a&amp;amp;i;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; run;&lt;BR /&gt;%mend createDims;&lt;BR /&gt;%createDims()&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CTorres&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jan 2015 16:18:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-A-character-operand-was-found-in-the-EVAL-function-or-IF/m-p/174946#M33605</guid>
      <dc:creator>CTorres</dc:creator>
      <dc:date>2015-01-08T16:18:56Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-A-character-operand-was-found-in-the-EVAL-function-or-IF/m-p/174947#M33606</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, that works with 1 record. Sorry, I should have included more records. I added the numDim to each line of the the dataset because I want to read it and use it for each line of the dataset&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;10&amp;nbsp; Smith&amp;nbsp; 123:199:256:277:600&lt;BR /&gt;11&amp;nbsp; Jones&amp;nbsp; 222:111&lt;BR /&gt;12&amp;nbsp; Jeddy&amp;nbsp; 555:758:987:111&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test_1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; length numDim 8.;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; set test;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; numDim=(countc(diag, ':')+1);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;should produce:&lt;/P&gt;&lt;P&gt;numDim&amp;nbsp; idno&amp;nbsp;&amp;nbsp; l_name&amp;nbsp; diag&lt;BR /&gt;5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Smith&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 123:199:256:277:600&lt;BR /&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Jones&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 222:111&lt;BR /&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Leddy&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 555:758:987:111&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jan 2015 16:29:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-A-character-operand-was-found-in-the-EVAL-function-or-IF/m-p/174947#M33606</guid>
      <dc:creator>robby_beum</dc:creator>
      <dc:date>2015-01-08T16:29:32Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-A-character-operand-was-found-in-the-EVAL-function-or-IF/m-p/174948#M33607</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I’ll try to add an explanation in case readers are wondering what’s going on in the solution suggested by CTorres. A %DO loop can be used to generate a block of SAS code repeatedly with different index values. However, since %DO is a macro statement, any variables in it would have to be macro variables. There are various ways to create macro variables, and the CALL SYMPUTX routine is a good approach if you want to create a macro variable from a a value in a data step. Then, once the macro variable exists, a macro variable reference has to begin with an ampersand — that’s what marks it as a macro variable. As originally presented, the %DO statement is looking at the text “numDim” in the %DO statement, rather than a variable. The %DO statement uses the %EVAL function to get the numeric value of its %TO argument, and this is why the error message refers to the %EVAL function.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jan 2015 16:38:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-A-character-operand-was-found-in-the-EVAL-function-or-IF/m-p/174948#M33607</guid>
      <dc:creator>RickAster</dc:creator>
      <dc:date>2015-01-08T16:38:56Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-A-character-operand-was-found-in-the-EVAL-function-or-IF/m-p/174949#M33608</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Now I understand.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You do not need macro languaje to solve the problem:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; input idno 1-2 l_name $ 5-9 diag $ 12-30;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; cards;&lt;BR /&gt;10&amp;nbsp; Smith&amp;nbsp; 123:199:256:277:600&lt;BR /&gt;11&amp;nbsp; Jones&amp;nbsp; 222:111&lt;BR /&gt;12&amp;nbsp; Jeddy&amp;nbsp; 555:758:987:111&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data test3;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; length numDim 8.;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; set test;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; numDim=(countc(diag, ':')+1);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; do i = 1 to numDim;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; diag_code=scan(diag, i, ':');&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; drop diag i;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks RiskAster for your explanation.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CTorres&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jan 2015 17:16:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-A-character-operand-was-found-in-the-EVAL-function-or-IF/m-p/174949#M33608</guid>
      <dc:creator>CTorres</dc:creator>
      <dc:date>2015-01-08T17:16:05Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-A-character-operand-was-found-in-the-EVAL-function-or-IF/m-p/174950#M33609</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I agree with CTorres. You don#t even need the numDim variable:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; input idno 1-2 l_name $ 5-9 diag $ 12-30;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; cards;&lt;BR /&gt;10&amp;nbsp; Smith&amp;nbsp; 123:199:256:277:600&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;Data Test_2 ;&lt;BR /&gt;&amp;nbsp; Set Test;&lt;BR /&gt;&amp;nbsp; Do i=1 To CountC(Diag,':')+1 By 1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Diag_Code=Scan(Diag,i,':');&lt;BR /&gt; Output;&lt;BR /&gt;&amp;nbsp; End;&lt;BR /&gt;Run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jan 2015 17:36:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-A-character-operand-was-found-in-the-EVAL-function-or-IF/m-p/174950#M33609</guid>
      <dc:creator>user24feb</dc:creator>
      <dc:date>2015-01-08T17:36:41Z</dc:date>
    </item>
  </channel>
</rss>

