<?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 proc SQL, convert numeric to character in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/proc-SQL-convert-numeric-to-character/m-p/60081#M17016</link>
    <description>Within proc SQL, is it possible to select a numeric column, then check it against character values without an error?  I've tried converting it to character but can't seem to get the syntax correct.&lt;BR /&gt;
&lt;BR /&gt;
If the variable mcc in table x is numeric, the following yeilds an error since mcc is numeric and the where statement contains character values:&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table a as select mcc&lt;BR /&gt;
from x&lt;BR /&gt;
where mcc in ('1234','5678');&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
Is there a way to convert mcc to character so the where statement works?  In case you are wondering, changing the where to values to numeric is not an option.&lt;BR /&gt;
&lt;BR /&gt;
Thanks</description>
    <pubDate>Tue, 03 Aug 2010 20:46:45 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2010-08-03T20:46:45Z</dc:date>
    <item>
      <title>proc SQL, convert numeric to character</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-SQL-convert-numeric-to-character/m-p/60081#M17016</link>
      <description>Within proc SQL, is it possible to select a numeric column, then check it against character values without an error?  I've tried converting it to character but can't seem to get the syntax correct.&lt;BR /&gt;
&lt;BR /&gt;
If the variable mcc in table x is numeric, the following yeilds an error since mcc is numeric and the where statement contains character values:&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table a as select mcc&lt;BR /&gt;
from x&lt;BR /&gt;
where mcc in ('1234','5678');&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
Is there a way to convert mcc to character so the where statement works?  In case you are wondering, changing the where to values to numeric is not an option.&lt;BR /&gt;
&lt;BR /&gt;
Thanks</description>
      <pubDate>Tue, 03 Aug 2010 20:46:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-SQL-convert-numeric-to-character/m-p/60081#M17016</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-08-03T20:46:45Z</dc:date>
    </item>
    <item>
      <title>Re: proc SQL, convert numeric to character</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-SQL-convert-numeric-to-character/m-p/60082#M17017</link>
      <description>Hi:&lt;BR /&gt;
  You should be seeing something like this ERROR message in the log:&lt;BR /&gt;
[pre]&lt;BR /&gt;
 &lt;BR /&gt;
ERROR: Expression using IN has components that are of different&lt;BR /&gt;
       data types.&lt;BR /&gt;
&lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
But, for purposes of WHERE, you can use the PUT function to convert the compared value to character for the duration of the comparison. See the program log below. &lt;BR /&gt;
&lt;BR /&gt;
cynthia&lt;BR /&gt;
[pre]&lt;BR /&gt;
9331  ods listing;&lt;BR /&gt;
9332  proc sql;&lt;BR /&gt;
9333    title 'bad sql where';&lt;BR /&gt;
9334    select *&lt;BR /&gt;
9335    from sashelp.class&lt;BR /&gt;
9336    where age in ('11','12','13')&lt;BR /&gt;
9337    order by age;&lt;BR /&gt;
ERROR: Expression using IN has components that are of different&lt;BR /&gt;
       data types.&lt;BR /&gt;
NOTE: The IN referred to may have been transformed from an OR&lt;BR /&gt;
      to an IN at some point during PROC SQL WHERE clause&lt;BR /&gt;
      optimization.&lt;BR /&gt;
9338  quit;&lt;BR /&gt;
NOTE: The SAS System stopped processing this step because of&lt;BR /&gt;
      errors.&lt;BR /&gt;
NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;
      real time           0.00 seconds&lt;BR /&gt;
      cpu time            0.00 seconds&lt;BR /&gt;
&lt;BR /&gt;
9339&lt;BR /&gt;
9340&lt;BR /&gt;
                                 &lt;BR /&gt;
                    &lt;BR /&gt;
9341  proc sql;&lt;BR /&gt;
9342    title 'good sql where';&lt;BR /&gt;
9343    select *&lt;BR /&gt;
9344    from sashelp.class&lt;BR /&gt;
9345    where put(age,2.0) in ('11','12','13')&lt;BR /&gt;
9346    order by age;&lt;BR /&gt;
9347  quit;&lt;BR /&gt;
NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;
      real time           0.10 seconds&lt;BR /&gt;
      cpu time            0.01 seconds&lt;BR /&gt;
&lt;BR /&gt;
[/pre]</description>
      <pubDate>Tue, 03 Aug 2010 21:00:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-SQL-convert-numeric-to-character/m-p/60082#M17017</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-08-03T21:00:11Z</dc:date>
    </item>
    <item>
      <title>Re: proc SQL, convert numeric to character</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-SQL-convert-numeric-to-character/m-p/60083#M17018</link>
      <description>You are exactly correct and your solution works.  Thank you very much.</description>
      <pubDate>Tue, 03 Aug 2010 21:51:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-SQL-convert-numeric-to-character/m-p/60083#M17018</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-08-03T21:51:05Z</dc:date>
    </item>
  </channel>
</rss>

