<?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: WHERE clause operator requires compatible variables. in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/ERROR-WHERE-clause-operator-requires-compatible-variables/m-p/897116#M39916</link>
    <description>I see. Thank you so much!!!!</description>
    <pubDate>Wed, 04 Oct 2023 10:10:06 GMT</pubDate>
    <dc:creator>bbibbi_yc</dc:creator>
    <dc:date>2023-10-04T10:10:06Z</dc:date>
    <item>
      <title>ERROR: WHERE clause operator requires compatible variables.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/ERROR-WHERE-clause-operator-requires-compatible-variables/m-p/897098#M39912</link>
      <description>&lt;P&gt;Hello, I use the WHERE to set my data, but the log shows the error like below:&lt;/P&gt;&lt;P&gt;And I'm wondering what's goes wrong.&lt;/P&gt;&lt;P&gt;Thank you.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc import datafile='/home/u63518324/sasuser.v94/Epi_test.xls'
out=homework_per
dbms=xls;
getnames=yes;
run;

data homework_1;set homework_per;
BMI=weight/(height*height)*10000;
if BMI&amp;lt;24 then BMI_group=1;
else if BMI&amp;gt;=24 then BMI_group=2;
run;

proc format;
value BMI_group 1='normal weight' 2='overweight';
run;

data homework_1;set homework_1;
format BMI_group BMI_group.;
run;

proc print data=homework_1 AND BMI_group='overweight';
where sex='F';
run;

proc print data=homework_1;
where BMI_group='overweight';
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=""&gt;ERROR: WHERE clause operator requires compatible variables.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Oct 2023 05:16:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/ERROR-WHERE-clause-operator-requires-compatible-variables/m-p/897098#M39912</guid>
      <dc:creator>bbibbi_yc</dc:creator>
      <dc:date>2023-10-04T05:16:37Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR: WHERE clause operator requires compatible variables.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/ERROR-WHERE-clause-operator-requires-compatible-variables/m-p/897099#M39913</link>
      <description>&lt;P&gt;Assuming that "and BMI_group ..." belongs to the where statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print data=homework_1;
where sex='F' AND BMI_group='overweight';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Attaching a format to a variable does not change the type of the variable, only the way its values are displayed changes. So BMI_group is still numeric and the comparison with "overweight" causes the error.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Oct 2023 05:27:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/ERROR-WHERE-clause-operator-requires-compatible-variables/m-p/897099#M39913</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2023-10-04T05:27:45Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR: WHERE clause operator requires compatible variables.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/ERROR-WHERE-clause-operator-requires-compatible-variables/m-p/897100#M39914</link>
      <description>&lt;P&gt;You need to amend your data step so variable bmi_group gets populated.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data homework_2;
  set homework_1;
  bmi_group=put(bmi,bmi_group.);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For just using a formatted value in a where clause you could also directly write code like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print data=homework_1;
  where put(bmi,BMI_group.)='overweight';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And if you then want to print the bmi values with a format applied you could code like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print data=homework_1;
  where put(bmi,BMI_group.)='overweight';
  format bmi bmi_group.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Oct 2023 05:57:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/ERROR-WHERE-clause-operator-requires-compatible-variables/m-p/897100#M39914</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-10-04T05:57:13Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR: WHERE clause operator requires compatible variables.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/ERROR-WHERE-clause-operator-requires-compatible-variables/m-p/897115#M39915</link>
      <description>&lt;P&gt;I follow your steps and solve the problem!&lt;/P&gt;&lt;P&gt;Thank you so much!!!!!!&lt;/P&gt;</description>
      <pubDate>Wed, 04 Oct 2023 10:11:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/ERROR-WHERE-clause-operator-requires-compatible-variables/m-p/897115#M39915</guid>
      <dc:creator>bbibbi_yc</dc:creator>
      <dc:date>2023-10-04T10:11:21Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR: WHERE clause operator requires compatible variables.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/ERROR-WHERE-clause-operator-requires-compatible-variables/m-p/897116#M39916</link>
      <description>I see. Thank you so much!!!!</description>
      <pubDate>Wed, 04 Oct 2023 10:10:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/ERROR-WHERE-clause-operator-requires-compatible-variables/m-p/897116#M39916</guid>
      <dc:creator>bbibbi_yc</dc:creator>
      <dc:date>2023-10-04T10:10:06Z</dc:date>
    </item>
  </channel>
</rss>

