<?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: A character operand was found in the %IF condition where a numeric operand is required in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/A-character-operand-was-found-in-the-IF-condition-where-a/m-p/762570#M241465</link>
    <description>&lt;P&gt;Yeah, that worked.&amp;nbsp; Not sure if I'll ever figure out the "%" and "." and "&amp;amp;" and "&amp;amp;&amp;amp;" syntaxes.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;But I've only been working in SAS 25 years......&amp;nbsp; &amp;nbsp;Does help to turn on&amp;nbsp;mprint mlogic symbolgen.&lt;/P&gt;</description>
    <pubDate>Thu, 19 Aug 2021 15:37:22 GMT</pubDate>
    <dc:creator>Jumboshrimps</dc:creator>
    <dc:date>2021-08-19T15:37:22Z</dc:date>
    <item>
      <title>A character operand was found in the %IF condition where a numeric operand is required</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-character-operand-was-found-in-the-IF-condition-where-a/m-p/762360#M241368</link>
      <description>&lt;P&gt;Below code works on it's own, producing&amp;nbsp; variable "EVENT" for every record. If pat_id has three records, then EVENT is 1 for first record of that PAT_ID, 2 for second record of that PAT_ID, 3 for third record of that PAT_ID.&amp;nbsp; Most pat_id's have less than 3 EVENT.&amp;nbsp; 300,000 or more total records, 119,000 unique pat_id's.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this example, we will select OPIOIDS, (there are over forty different medication types, spread over 2,200 lines of code - same set of procedures was cut-and-pasted 40 times by the guy before me).&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;data OPIOID2 (Drop=n count);&lt;BR /&gt;format EVENT 6.;&lt;BR /&gt;set OPIOID1;&lt;BR /&gt;by PAT_ID;&lt;BR /&gt;n=_N_;&lt;BR /&gt;retain count;&lt;BR /&gt;if first.PAT_ID then count=n;&lt;BR /&gt;EVENT=n-count+1;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Works fine, produces a much smaller data set with variable EVENT incremented plus 1 per set of PAT_ID records.&lt;/P&gt;
&lt;P&gt;In my attempt to "macrotize" this code and just run this one macro 40 times, eliminating 2,200 lines of superfluous code,(this is the second step of four, the first attempt to make a macro of the proc sql runs fine, as do steps three - transpose the data, and four, make a big long string from&amp;nbsp; concatenating the variables in the transposed data,&amp;nbsp; passing just one parameter &amp;amp;MED.)&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;The macro code below generates the following error:&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;" A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: first.PAT_ID"&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;PAT_ID is a char variable of 18 len.&amp;nbsp; Some pat_id's are left padded with "0" - up to five of them. Half are are all numbers. Other half of the Pat_id's start with alpha characters.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;I don't understand how the code above has no errors, but the code below does.&amp;nbsp; PAT_ID is the same variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro EVNT(MED);&lt;/P&gt;
&lt;P&gt;data &amp;amp;MED.2 (Drop=n count);&lt;BR /&gt;LENGTH EVENT 6.;&lt;BR /&gt;set &amp;amp;MED.1;&amp;nbsp; /*macro for proc sql selection of the MED works fine.&lt;BR /&gt;by PAT_ID;&lt;BR /&gt;n=_N_;&lt;BR /&gt;retain count;&lt;BR /&gt;%if first.PAT_ID %then count=n;&lt;BR /&gt;EVENT=n-count+1;&lt;BR /&gt;%MEND;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%EVNT(OPIOID);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;THX.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Aug 2021 19:20:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-character-operand-was-found-in-the-IF-condition-where-a/m-p/762360#M241368</guid>
      <dc:creator>Jumboshrimps</dc:creator>
      <dc:date>2021-08-18T19:20:19Z</dc:date>
    </item>
    <item>
      <title>Re: A character operand was found in the %IF condition where a numeric operand is required</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-character-operand-was-found-in-the-IF-condition-where-a/m-p/762362#M241369</link>
      <description>&lt;P&gt;There's no need to use %IF-%THEN processing here. You just need to stick with IF-THEN.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro EVNT(MED);

data &amp;amp;MED.2 (Drop=n count);
LENGTH EVENT 6.;
set &amp;amp;MED.1;  /*macro for proc sql selection of the MED works fine.
by PAT_ID;
n=_N_;
retain count;
if first.PAT_ID then count=n;
EVENT=n-count+1;
%MEND;

 

%EVNT(OPIOID);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Unless I'm seriously misunderstanding something. %IF-%THEN deals with macro processing and processing macro variables. You're not doing anything with the MED macro variable parameter other than setting it with the name OPIOID.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Taken from &lt;A href="http://Although they look similar, the %IF-%THEN/%ELSE statement and the IF-THEN/ELSE statement belong to two different languages. In general, %IF-%THEN/%ELSE statement, which is part of the SAS macro language, conditionally generates text. However, the IF-THEN/ELSE statement, which is part of the SAS language, conditionally executes SAS statements during DATA step execution. " target="_self"&gt;here:&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Although they look similar, the %IF-%THEN/%ELSE statement and the IF-THEN/ELSE statement belong to two different languages. In general, %IF-%THEN/%ELSE statement, which is part of the SAS macro language, conditionally generates text. However, the IF-THEN/ELSE statement, which is part of the SAS language, conditionally executes SAS statements during DATA step execution.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Wed, 18 Aug 2021 19:26:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-character-operand-was-found-in-the-IF-condition-where-a/m-p/762362#M241369</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2021-08-18T19:26:16Z</dc:date>
    </item>
    <item>
      <title>Re: A character operand was found in the %IF condition where a numeric operand is required</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-character-operand-was-found-in-the-IF-condition-where-a/m-p/762369#M241375</link>
      <description>&lt;P&gt;My explanation:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IF-THEN-ELSE works on data set variables&lt;/P&gt;
&lt;P&gt;%IF-%THEN-%ELSE works on macro variables, and doesn't know about data set variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you cannot use %IF first.pat_id because %IF is looking for a macro variable and doesn't know what first.pat_id is.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When trying to debug macro issues, run this command&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint mlogic symbolgen;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;before you run the macro. Then, show us the &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;ENTIRE&lt;/STRONG&gt; &lt;/FONT&gt;log for the macro, not just the error message and not selected portions of the log. Never separate error messages from the code in the log that produced the error.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Aug 2021 19:59:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-character-operand-was-found-in-the-IF-condition-where-a/m-p/762369#M241375</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-08-18T19:59:50Z</dc:date>
    </item>
    <item>
      <title>Re: A character operand was found in the %IF condition where a numeric operand is required</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-character-operand-was-found-in-the-IF-condition-where-a/m-p/762374#M241379</link>
      <description>&lt;P&gt;Create two copies of your working data step for two different sets of input/output datasets.&lt;/P&gt;
&lt;P&gt;ONE:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data OPIOID2 (Drop=n count);
format EVENT 6.;
set OPIOID1;
by PAT_ID;
n=_N_;
retain count;
if first.PAT_ID then count=n;
EVENT=n-count+1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;TWO:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data NSAID2(Drop=n count);
format EVENT 6.;
set NSAID1;
by PAT_ID;
n=_N_;
retain count;
if first.PAT_ID then count=n;
EVENT=n-count+1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Compare with a text comparison tool.&lt;/P&gt;
&lt;P&gt;Then when creating a macro only modify that parts that differ.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Aug 2021 20:15:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-character-operand-was-found-in-the-IF-condition-where-a/m-p/762374#M241379</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-08-18T20:15:21Z</dc:date>
    </item>
    <item>
      <title>Re: A character operand was found in the %IF condition where a numeric operand is required</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-character-operand-was-found-in-the-IF-condition-where-a/m-p/762570#M241465</link>
      <description>&lt;P&gt;Yeah, that worked.&amp;nbsp; Not sure if I'll ever figure out the "%" and "." and "&amp;amp;" and "&amp;amp;&amp;amp;" syntaxes.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;But I've only been working in SAS 25 years......&amp;nbsp; &amp;nbsp;Does help to turn on&amp;nbsp;mprint mlogic symbolgen.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Aug 2021 15:37:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-character-operand-was-found-in-the-IF-condition-where-a/m-p/762570#M241465</guid>
      <dc:creator>Jumboshrimps</dc:creator>
      <dc:date>2021-08-19T15:37:22Z</dc:date>
    </item>
  </channel>
</rss>

