<?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: WHERE clause operator requires compatible variables Error in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/WHERE-clause-operator-requires-compatible-variables-Error/m-p/709620#M218259</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The where statement in a data step has a global effect and drops the observations that don't&lt;/P&gt;
&lt;P&gt;match the condition before executing the data step intructions.&lt;/P&gt;
&lt;P&gt;Thus, it does not make sense to condition these where statements as they will all be taken into account&lt;/P&gt;
&lt;P&gt;at the program execution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Before resolving this type mismatch problem, you might want to reconsider the logic of&lt;/P&gt;
&lt;P&gt;your program.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you explain on a simplified example what you are trying to achieve ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 06 Jan 2021 13:54:09 GMT</pubDate>
    <dc:creator>gamotte</dc:creator>
    <dc:date>2021-01-06T13:54:09Z</dc:date>
    <item>
      <title>WHERE clause operator requires compatible variables Error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/WHERE-clause-operator-requires-compatible-variables-Error/m-p/709609#M218257</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have this SAS code that I need to use so I can have the snomed codes to cover all the types of result texts that I have in excel sheet.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if test_loinc="94558-4" then do; /*Note: this is an antigen test*/&lt;BR /&gt;result_snomed=10828004;&lt;BR /&gt;where (test_result="Positive"&lt;BR /&gt;or test_result="POSITIVE"&lt;BR /&gt;or test_result="positive");&lt;BR /&gt;result_snomed=260373001;&lt;BR /&gt;where (test_result="Detected"&lt;BR /&gt;or test_result="DETECTED"&lt;BR /&gt;or test_result="detected");&lt;BR /&gt;result_snomed=260385009;&lt;BR /&gt;where (test_result="Negative"&lt;BR /&gt;or test_result="NEGATIVE"&lt;BR /&gt;or test_result="negative");&lt;BR /&gt;result_snomed=260415000;&lt;BR /&gt;where (test_result="Not Detected"&lt;BR /&gt;or test_result="NOT DETECTED"&lt;BR /&gt;or test_result="not detected"&lt;BR /&gt;or test_result="Not detected");&lt;BR /&gt;end;&lt;BR /&gt;else if test_loinc="94759-8" then do; /*Note: this is a PCR test*/&lt;BR /&gt;result_snomed=10828004;&lt;BR /&gt;where (test_result="Positive"&lt;BR /&gt;or test_result="POSITIVE"&lt;BR /&gt;or test_result="positive");&lt;BR /&gt;result_snomed=260373001;&lt;BR /&gt;where (test_result="Detected"&lt;BR /&gt;or test_result="DETECTED"&lt;BR /&gt;or test_result="detected");&lt;BR /&gt;result_snomed=125154007;&lt;BR /&gt;where (test_result="Unsatisfactory"&lt;BR /&gt;or test_result="UNSATISFACTORY"&lt;BR /&gt;or test_result="unsatisfactory");&lt;BR /&gt;result_snomed=260385009;&lt;BR /&gt;where (test_result="Negative"&lt;BR /&gt;or test_result="NEGATIVE"&lt;BR /&gt;or test_result="negative");&lt;BR /&gt;result_snomed=260415000;&lt;BR /&gt;where (test_result="Not Detected"&lt;BR /&gt;or test_result="NOT DETECTED"&lt;BR /&gt;or test_result="not detected"&lt;BR /&gt;or test_result="Not detected");&lt;BR /&gt;result_snomed=280416009;&lt;BR /&gt;where (test_result="Indeterminate"&lt;BR /&gt;or test_result="INDETERMINATE"&lt;BR /&gt;or test_result="indeterminate");&lt;BR /&gt;result_snomed=419984006;&lt;BR /&gt;where (test_result="Inconclusive"&lt;BR /&gt;or test_result="INCONCLUSIVE"&lt;BR /&gt;or test_result="inconclusive");&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;First thing I got this error (after each if statement):&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;if test_loinc="94558-4" then do; /*Note: this is an antigen test*/&lt;BR /&gt;220 result_snomed=10828004;&lt;BR /&gt;221 where (test_result="Positive"&lt;BR /&gt;222 or test_result="POSITIVE"&lt;BR /&gt;223 or test_result="positive");&lt;BR /&gt;ERROR: WHERE clause operator requires compatible variables.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Also is there another simpler way to do this rather than having this long code?&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jan 2021 13:16:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/WHERE-clause-operator-requires-compatible-variables-Error/m-p/709609#M218257</guid>
      <dc:creator>mayasak</dc:creator>
      <dc:date>2021-01-06T13:16:42Z</dc:date>
    </item>
    <item>
      <title>Re: WHERE clause operator requires compatible variables Error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/WHERE-clause-operator-requires-compatible-variables-Error/m-p/709613#M218258</link>
      <description>&lt;P&gt;You are trying to compare a numeric variable named TEST_RESULT to a character string. You can't do that. You have to compare numeric to numeric, or character to character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;it is possible that numeric TEST_RESULT is formatted to appear as character; that would still require you to compare it to a numeric value. Use PROC CONTENTS to find out how TEST_RESULT is formatted.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jan 2021 13:42:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/WHERE-clause-operator-requires-compatible-variables-Error/m-p/709613#M218258</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-01-06T13:42:06Z</dc:date>
    </item>
    <item>
      <title>Re: WHERE clause operator requires compatible variables Error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/WHERE-clause-operator-requires-compatible-variables-Error/m-p/709620#M218259</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The where statement in a data step has a global effect and drops the observations that don't&lt;/P&gt;
&lt;P&gt;match the condition before executing the data step intructions.&lt;/P&gt;
&lt;P&gt;Thus, it does not make sense to condition these where statements as they will all be taken into account&lt;/P&gt;
&lt;P&gt;at the program execution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Before resolving this type mismatch problem, you might want to reconsider the logic of&lt;/P&gt;
&lt;P&gt;your program.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you explain on a simplified example what you are trying to achieve ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jan 2021 13:54:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/WHERE-clause-operator-requires-compatible-variables-Error/m-p/709620#M218259</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2021-01-06T13:54:09Z</dc:date>
    </item>
    <item>
      <title>Re: WHERE clause operator requires compatible variables Error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/WHERE-clause-operator-requires-compatible-variables-Error/m-p/709623#M218261</link>
      <description>&lt;P&gt;You have two serious mistakes here:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;trying to have a conditional WHERE statement. This is not possible, see the&amp;nbsp;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lestmtsref&amp;amp;docsetTarget=n1xbr9r0s9veq0n137iftzxq4g7e.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;documentation&lt;/A&gt;.&lt;/LI&gt;
&lt;LI&gt;having multiple WHERE statements. Only the&amp;nbsp;&lt;EM&gt;last&lt;/EM&gt; WHERE statement will be compiled by the data step compiler.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;I&amp;nbsp;&lt;EM&gt;guess&lt;/EM&gt; that you should use the conditions in the IF statements; for more detailed help, supply some example data in usable form (DATA step with DATALINES,&amp;nbsp;&lt;STRONG&gt;NOT&amp;nbsp;&lt;/STRONG&gt;Excel files or screenshots!), and what you intend to have as a result from that.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jan 2021 14:04:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/WHERE-clause-operator-requires-compatible-variables-Error/m-p/709623#M218261</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-01-06T14:04:57Z</dc:date>
    </item>
    <item>
      <title>Re: WHERE clause operator requires compatible variables Error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/WHERE-clause-operator-requires-compatible-variables-Error/m-p/709632#M218264</link>
      <description>&lt;PRE&gt;data;
   input name $ test_loinc $ test_result $;
   datalines;
John 94759-8 Positive
Michelle 94558-4 Not detected&lt;BR /&gt;Grace 94759-8 DETECTED
;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;
&lt;P&gt;So the issue is that we're getting an excel sheet from a hospital that have different variables (in additition to the test_result and test_loinc) and we need to import into to our system. They use only 2 loincs (tests) (used in the example) and the result comes in different formats such as DETECTED, Detected, Positive, positive... etc. What I needed to do is to code all different result formats into the standard snomed (results) codes such as &lt;SPAN&gt;10828004 for all postive results because our system accepts only codes for loincs and snomeds. BTW I'm not sure if the test_result is a character or numerical but I'm assuming it's a character in the example! Thank you&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;    &amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jan 2021 15:01:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/WHERE-clause-operator-requires-compatible-variables-Error/m-p/709632#M218264</guid>
      <dc:creator>mayasak</dc:creator>
      <dc:date>2021-01-06T15:01:31Z</dc:date>
    </item>
    <item>
      <title>Re: WHERE clause operator requires compatible variables Error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/WHERE-clause-operator-requires-compatible-variables-Error/m-p/709638#M218265</link>
      <description>&lt;P&gt;Can you show us a portion of the data set from the imported spreadsheet by following &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;these instructions&lt;/A&gt;&amp;nbsp;, and not via any other method. Do not attach the Excel file, most people will not download it.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jan 2021 15:13:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/WHERE-clause-operator-requires-compatible-variables-Error/m-p/709638#M218265</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-01-06T15:13:53Z</dc:date>
    </item>
    <item>
      <title>Re: WHERE clause operator requires compatible variables Error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/WHERE-clause-operator-requires-compatible-variables-Error/m-p/709652#M218270</link>
      <description>&lt;P&gt;Start with a "brute force" approach like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select (test_loinc);
  when ("94759-8") do;
    select (upcase(test_result));
      when ("POSITIVE") result_snomed = 260373001;
      when ("DETECTED") result_snomed = 260385009;
      otherwise result_snomed = 10828004;
    end;
  end;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;expand this code snippet for the other tests and results.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jan 2021 16:19:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/WHERE-clause-operator-requires-compatible-variables-Error/m-p/709652#M218270</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-01-06T16:19:45Z</dc:date>
    </item>
    <item>
      <title>Re: WHERE clause operator requires compatible variables Error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/WHERE-clause-operator-requires-compatible-variables-Error/m-p/709673#M218277</link>
      <description>&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;I expanded this to:&lt;/P&gt;&lt;P&gt;select (test_loinc);&lt;BR /&gt;when ("94759-8") do;&lt;BR /&gt;select (upcase(test_result));&lt;BR /&gt;when ("DETECTED") result_snomed = 260373001;&lt;BR /&gt;when ("NEGATIVE") result_snomed = 260385009;&lt;BR /&gt;when ("POSITIVE") result_snomed = 10828004;&lt;BR /&gt;otherwise result_snomed = 260415000;&lt;BR /&gt;end;&lt;BR /&gt;select (lowcase(test_result));&lt;BR /&gt;when ("detected") result_snomed = 260373001;&lt;BR /&gt;when ("negative") result_snomed = 260385009;&lt;BR /&gt;when ("positive") result_snomed = 10828004;&lt;BR /&gt;otherwise result_snomed = 260415000;&lt;BR /&gt;end;&lt;BR /&gt;select (propcase(test_result));&lt;BR /&gt;when ("Detected") result_snomed = 260373001;&lt;BR /&gt;when ("Negative") result_snomed = 260385009;&lt;BR /&gt;when ("Positive") result_snomed = 10828004;&lt;BR /&gt;otherwise result_snomed = 260415000;&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;when ("94558-4") do;&lt;BR /&gt;select (upcase(test_result));&lt;BR /&gt;when ("DETECTED") result_snomed = 260373001;&lt;BR /&gt;when ("NEGATIVE") result_snomed = 260385009;&lt;BR /&gt;when ("POSITIVE") result_snomed = 10828004;&lt;BR /&gt;otherwise result_snomed = 260415000;&lt;BR /&gt;end;&lt;BR /&gt;select (lowcase(test_result));&lt;BR /&gt;when ("detected") result_snomed = 260373001;&lt;BR /&gt;when ("negative") result_snomed = 260385009;&lt;BR /&gt;when ("positive") result_snomed = 10828004;&lt;BR /&gt;otherwise result_snomed = 260415000;&lt;BR /&gt;end;&lt;BR /&gt;select (propcase(test_result));&lt;BR /&gt;when ("Detected") result_snomed = 260373001;&lt;BR /&gt;when ("Negative") result_snomed = 260385009;&lt;BR /&gt;when ("Positive") result_snomed = 10828004;&lt;BR /&gt;otherwise result_snomed = 260415000;&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does it look fine? Especially for the use of end;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;Razina&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jan 2021 18:17:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/WHERE-clause-operator-requires-compatible-variables-Error/m-p/709673#M218277</guid>
      <dc:creator>mayasak</dc:creator>
      <dc:date>2021-01-06T18:17:27Z</dc:date>
    </item>
    <item>
      <title>Re: WHERE clause operator requires compatible variables Error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/WHERE-clause-operator-requires-compatible-variables-Error/m-p/709675#M218279</link>
      <description>I don't understand what you are trying to do.&lt;BR /&gt;&lt;BR /&gt;You do exactly the same thing for the different values of test_loinc  so why distinguishing several cases ?&lt;BR /&gt;&lt;BR /&gt;Also, for a given value of test_loinc all selects after the first one are redundants since&lt;BR /&gt;they test the same condition (although expressed differently).&lt;BR /&gt;&lt;BR /&gt;=&amp;gt; All your code could be replaced by (under the assumption that there are no other values for test_loinc) :&lt;BR /&gt;select (upcase(test_result));&lt;BR /&gt;when ("DETECTED") result_snomed = 260373001;&lt;BR /&gt;when ("NEGATIVE") result_snomed = 260385009;&lt;BR /&gt;when ("POSITIVE") result_snomed = 10828004;&lt;BR /&gt;otherwise result_snomed = 260415000;&lt;BR /&gt;end;</description>
      <pubDate>Wed, 06 Jan 2021 18:40:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/WHERE-clause-operator-requires-compatible-variables-Error/m-p/709675#M218279</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2021-01-06T18:40:13Z</dc:date>
    </item>
    <item>
      <title>Re: WHERE clause operator requires compatible variables Error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/WHERE-clause-operator-requires-compatible-variables-Error/m-p/709686#M218285</link>
      <description>&lt;P&gt;There are 2 values for "test_loinc" and more values for "test_result" such as results with all lower case and results with mixedletters (first letter only upper case).&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;Razina&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jan 2021 19:13:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/WHERE-clause-operator-requires-compatible-variables-Error/m-p/709686#M218285</guid>
      <dc:creator>mayasak</dc:creator>
      <dc:date>2021-01-06T19:13:51Z</dc:date>
    </item>
    <item>
      <title>Re: WHERE clause operator requires compatible variables Error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/WHERE-clause-operator-requires-compatible-variables-Error/m-p/709691#M218288</link>
      <description>&lt;P&gt;What &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/30622"&gt;@gamotte&lt;/a&gt;&amp;nbsp;said. By testing for UPCASE once you can cover all eventualities, most of your code is redundant.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jan 2021 19:50:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/WHERE-clause-operator-requires-compatible-variables-Error/m-p/709691#M218288</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-01-06T19:50:29Z</dc:date>
    </item>
  </channel>
</rss>

