<?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: Joining ON character and numeric variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Joining-ON-character-and-numeric-variable/m-p/559498#M156232</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/271494"&gt;@jffeudo86&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have 2 tables I need to join by a variable.&amp;nbsp; The thing is they have different types.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;Variable&lt;/TD&gt;
&lt;TD&gt;Type&lt;/TD&gt;
&lt;TD&gt;Len&lt;/TD&gt;
&lt;TD&gt;Format&lt;/TD&gt;
&lt;TD&gt;Informat&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Table A&lt;/TD&gt;
&lt;TD&gt;xx&lt;/TD&gt;
&lt;TD&gt;Char&lt;/TD&gt;
&lt;TD&gt;8&lt;/TD&gt;
&lt;TD&gt;$CHAR8.&lt;/TD&gt;
&lt;TD&gt;$CHAR8.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Table B&lt;/TD&gt;
&lt;TD&gt;xx&lt;/TD&gt;
&lt;TD&gt;Num&lt;/TD&gt;
&lt;TD&gt;8&lt;/TD&gt;
&lt;TD&gt;19.&lt;/TD&gt;
&lt;TD&gt;19.&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need the join statement.&amp;nbsp; I tried below and returned no rows. Is my join correct?&amp;nbsp; Please only focus on the JOIN clause and not any other part of the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;select *&lt;/P&gt;
&lt;P&gt;from tableA a&lt;/P&gt;
&lt;P&gt;inner join tableB b on input(a.xx, 8.) = b.xx;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;One would suspect that if you have a default format of 19. for a numeric variable that perhaps in needs more than 8 digits to represented which means that your other variable may be missing enough characters to make matches.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suggest a small experiment just creating values with your input as shown, ignore the other set, and see what values you get. Do they look like the ones in b?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You really should show us some example values that you expect to match.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 16 May 2019 21:47:57 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-05-16T21:47:57Z</dc:date>
    <item>
      <title>Joining ON character and numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Joining-ON-character-and-numeric-variable/m-p/559496#M156230</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 2 tables I need to join by a variable.&amp;nbsp; The thing is they have different types.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Variable&lt;/TD&gt;&lt;TD&gt;Type&lt;/TD&gt;&lt;TD&gt;Len&lt;/TD&gt;&lt;TD&gt;Format&lt;/TD&gt;&lt;TD&gt;Informat&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Table A&lt;/TD&gt;&lt;TD&gt;xx&lt;/TD&gt;&lt;TD&gt;Char&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;$CHAR8.&lt;/TD&gt;&lt;TD&gt;$CHAR8.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Table B&lt;/TD&gt;&lt;TD&gt;xx&lt;/TD&gt;&lt;TD&gt;Num&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;19.&lt;/TD&gt;&lt;TD&gt;19.&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need the join statement.&amp;nbsp; I tried below and returned no rows. Is my join correct?&amp;nbsp; Please only focus on the JOIN clause and not any other part of the code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;select *&lt;/P&gt;&lt;P&gt;from tableA a&lt;/P&gt;&lt;P&gt;inner join tableB b on input(a.xx, 8.) = b.xx;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 16 May 2019 21:37:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Joining-ON-character-and-numeric-variable/m-p/559496#M156230</guid>
      <dc:creator>jffeudo86</dc:creator>
      <dc:date>2019-05-16T21:37:20Z</dc:date>
    </item>
    <item>
      <title>Re: Joining ON character and numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Joining-ON-character-and-numeric-variable/m-p/559498#M156232</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/271494"&gt;@jffeudo86&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have 2 tables I need to join by a variable.&amp;nbsp; The thing is they have different types.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;Variable&lt;/TD&gt;
&lt;TD&gt;Type&lt;/TD&gt;
&lt;TD&gt;Len&lt;/TD&gt;
&lt;TD&gt;Format&lt;/TD&gt;
&lt;TD&gt;Informat&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Table A&lt;/TD&gt;
&lt;TD&gt;xx&lt;/TD&gt;
&lt;TD&gt;Char&lt;/TD&gt;
&lt;TD&gt;8&lt;/TD&gt;
&lt;TD&gt;$CHAR8.&lt;/TD&gt;
&lt;TD&gt;$CHAR8.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Table B&lt;/TD&gt;
&lt;TD&gt;xx&lt;/TD&gt;
&lt;TD&gt;Num&lt;/TD&gt;
&lt;TD&gt;8&lt;/TD&gt;
&lt;TD&gt;19.&lt;/TD&gt;
&lt;TD&gt;19.&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need the join statement.&amp;nbsp; I tried below and returned no rows. Is my join correct?&amp;nbsp; Please only focus on the JOIN clause and not any other part of the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;select *&lt;/P&gt;
&lt;P&gt;from tableA a&lt;/P&gt;
&lt;P&gt;inner join tableB b on input(a.xx, 8.) = b.xx;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;One would suspect that if you have a default format of 19. for a numeric variable that perhaps in needs more than 8 digits to represented which means that your other variable may be missing enough characters to make matches.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suggest a small experiment just creating values with your input as shown, ignore the other set, and see what values you get. Do they look like the ones in b?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You really should show us some example values that you expect to match.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 May 2019 21:47:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Joining-ON-character-and-numeric-variable/m-p/559498#M156232</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-05-16T21:47:57Z</dc:date>
    </item>
    <item>
      <title>Re: Joining ON character and numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Joining-ON-character-and-numeric-variable/m-p/559513#M156240</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/271494"&gt;@jffeudo86&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The join as posted should be o.k. so it's either something in the data or your actual join is different from what you show us.&lt;/P&gt;
&lt;P&gt;When inspecting the keys in your source data can you identify at least one case where you'd expect a match?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tableA;
  attrib xx format=$char8. informat=$char8.;
  do xx='1','2','3';
    xx=' '||xx;
    len_a_xx=lengthn(xx);
    output;
  end;
  stop;
run;

data tableB;
  attrib xx format=19. informat=19.;
  do xx=1,3,4;
    output;
  end;
  stop;
run;

proc sql;
  select 
    a.xx as a_xx, 
    len_a_xx,
    b.xx as b_xx
  from 
    tableA a inner join tableB b 
      on input(a.xx, 8.) = b.xx
  ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 149px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29584iE350330E90D7339C/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 16 May 2019 23:12:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Joining-ON-character-and-numeric-variable/m-p/559513#M156240</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-05-16T23:12:31Z</dc:date>
    </item>
    <item>
      <title>Re: Joining ON character and numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Joining-ON-character-and-numeric-variable/m-p/559637#M156304</link>
      <description>Thank you! New to SAS so I just wanted to know that my join is correct, or if not, be given direction on how to do it.</description>
      <pubDate>Fri, 17 May 2019 12:15:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Joining-ON-character-and-numeric-variable/m-p/559637#M156304</guid>
      <dc:creator>jffeudo86</dc:creator>
      <dc:date>2019-05-17T12:15:36Z</dc:date>
    </item>
  </channel>
</rss>

