<?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: Incompatible variables WHERE clause in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Incompatible-variables-WHERE-clause/m-p/328821#M73471</link>
    <description>&lt;P&gt;Why not save yourself a bit of coding, and messing around with macro lists:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table WANT as
  select *
  from   HAVE
  where ID in (select ID from NEW_ID where DATE &amp;lt; '01JAN2011'd);
quit;&lt;/PRE&gt;</description>
    <pubDate>Tue, 31 Jan 2017 17:09:05 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-01-31T17:09:05Z</dc:date>
    <item>
      <title>Incompatible variables WHERE clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Incompatible-variables-WHERE-clause/m-p/328800#M73456</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First I am putting a list of IDs in a macro variable from a dataset, then I'm using that macro variable in a where dataset option&amp;nbsp;for an different incoming dataset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;                              
 select ID into :ID_List_2010 separated by ' '
 from New_ID
 where date &amp;lt; '01jan2011'd;
quit;

data want;
  set have(where=(ID in(&amp;amp;ID_List_2010)));
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But I get this error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;FONT color="#FF0000"&gt;WHERE clause operator requires compatible variables.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;-ID in have is char of 15 length.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;-ID in New_ID is a char of 7 length.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;-Some IDs start with a 0.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;How do I get around this error? Thanks.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2017 16:20:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Incompatible-variables-WHERE-clause/m-p/328800#M73456</guid>
      <dc:creator>JediApprentice</dc:creator>
      <dc:date>2017-01-31T16:20:22Z</dc:date>
    </item>
    <item>
      <title>Re: Incompatible variables WHERE clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Incompatible-variables-WHERE-clause/m-p/328802#M73457</link>
      <description>%put &amp;amp;ID_List_2010;&lt;BR /&gt;and you'll see what's happening. &lt;BR /&gt;Or use OPTIONS SYMBOLGEN;</description>
      <pubDate>Tue, 31 Jan 2017 16:26:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Incompatible-variables-WHERE-clause/m-p/328802#M73457</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2017-01-31T16:26:44Z</dc:date>
    </item>
    <item>
      <title>Re: Incompatible variables WHERE clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Incompatible-variables-WHERE-clause/m-p/328805#M73458</link>
      <description>&lt;P&gt;And post actual log. You have TWO where clauses? Which one threw the error? Could your DATE variable not be a SAS date value and is perhaps character?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And no need for macro variables if the only use to match them in HAVE.&lt;/P&gt;
&lt;PRE&gt;proc sql;
   create table want as
   select have.*
   from (select * from New_id where date&amp;lt;'01JAN2011'd) left join
        have on New_id.id = have.id;
quit;&lt;/PRE&gt;</description>
      <pubDate>Tue, 31 Jan 2017 16:36:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Incompatible-variables-WHERE-clause/m-p/328805#M73458</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-01-31T16:36:34Z</dc:date>
    </item>
    <item>
      <title>Re: Incompatible variables WHERE clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Incompatible-variables-WHERE-clause/m-p/328812#M73462</link>
      <description>&lt;P&gt;To illustrate what Linus is getting at ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your macro variable looks something like this:&amp;nbsp; abc def xyz&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So your SET statement looks something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;set have (where=(ID in (abc def xyz)));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That's the wrong syntax when ID is a character variable.&amp;nbsp; You would need:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;set have (where=(ID in ("abc" "def" "xyz")));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So when SQL creates your macro variable, you need to add quotes around the ID values that it extracts.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2017 16:53:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Incompatible-variables-WHERE-clause/m-p/328812#M73462</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-01-31T16:53:45Z</dc:date>
    </item>
    <item>
      <title>Re: Incompatible variables WHERE clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Incompatible-variables-WHERE-clause/m-p/328813#M73463</link>
      <description>&lt;P&gt;I see, yes. What I did to solve it was:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select catt("'",ID,"'") into :ID_List_2010 separated by ', '&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2017 16:57:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Incompatible-variables-WHERE-clause/m-p/328813#M73463</guid>
      <dc:creator>JediApprentice</dc:creator>
      <dc:date>2017-01-31T16:57:28Z</dc:date>
    </item>
    <item>
      <title>Re: Incompatible variables WHERE clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Incompatible-variables-WHERE-clause/m-p/328815#M73465</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;Sorry I was not more specific about which one was having the issue - the where clause with the date was fine, it was the one with the ID.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2017 16:58:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Incompatible-variables-WHERE-clause/m-p/328815#M73465</guid>
      <dc:creator>JediApprentice</dc:creator>
      <dc:date>2017-01-31T16:58:53Z</dc:date>
    </item>
    <item>
      <title>Re: Incompatible variables WHERE clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Incompatible-variables-WHERE-clause/m-p/328816#M73466</link>
      <description>&lt;P&gt;Try select quote(id) instead of the CATT.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2017 17:00:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Incompatible-variables-WHERE-clause/m-p/328816#M73466</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-01-31T17:00:16Z</dc:date>
    </item>
    <item>
      <title>Re: Incompatible variables WHERE clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Incompatible-variables-WHERE-clause/m-p/328818#M73468</link>
      <description>&lt;P&gt;You can use either nested sql select as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;posted,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or change your code to:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;                              
 select ID into :ID_List_2010 separated by '" "'
 from New_ID
 where date &amp;lt; '01jan2011'd;
quit;

data want;
  set have(where=(ID in("&amp;amp;ID_List_2010")));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 31 Jan 2017 17:02:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Incompatible-variables-WHERE-clause/m-p/328818#M73468</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-01-31T17:02:15Z</dc:date>
    </item>
    <item>
      <title>Re: Incompatible variables WHERE clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Incompatible-variables-WHERE-clause/m-p/328820#M73470</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt;&amp;nbsp;I see, that one's pretty interesting because you account for the missing quotes at the beginning and end of the list by putting quotes around the macro variable reference.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2017 17:07:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Incompatible-variables-WHERE-clause/m-p/328820#M73470</guid>
      <dc:creator>JediApprentice</dc:creator>
      <dc:date>2017-01-31T17:07:48Z</dc:date>
    </item>
    <item>
      <title>Re: Incompatible variables WHERE clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Incompatible-variables-WHERE-clause/m-p/328821#M73471</link>
      <description>&lt;P&gt;Why not save yourself a bit of coding, and messing around with macro lists:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table WANT as
  select *
  from   HAVE
  where ID in (select ID from NEW_ID where DATE &amp;lt; '01JAN2011'd);
quit;&lt;/PRE&gt;</description>
      <pubDate>Tue, 31 Jan 2017 17:09:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Incompatible-variables-WHERE-clause/m-p/328821#M73471</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-01-31T17:09:05Z</dc:date>
    </item>
  </channel>
</rss>

