<?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: left join  variables type in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/left-join-variables-type/m-p/558574#M155906</link>
    <description>&lt;P&gt;You cannot fit 15 digits in a character variable with only 12 bytes. If you actually have numbers with 15 digits, these can never match.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please supply examples for your character and numeric values.&lt;/P&gt;</description>
    <pubDate>Tue, 14 May 2019 10:43:02 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2019-05-14T10:43:02Z</dc:date>
    <item>
      <title>left join  variables type</title>
      <link>https://communities.sas.com/t5/SAS-Programming/left-join-variables-type/m-p/558572#M155905</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I need to join two sas tables using left join,&amp;nbsp; the problem is that&amp;nbsp;&lt;/P&gt;&lt;P&gt;N1 type is 12$. and N2 is a numeric 15.&amp;nbsp;&lt;/P&gt;&lt;P&gt;i try to convert N2 to a character 15$. using a new variable N3 =put(N2,15$.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but sas couldn't find a matches between the two tables, that was confirmed by the full join,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;could you help me with that,&lt;/P&gt;&lt;P&gt;thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc SQL;&lt;BR /&gt;create table C as select&lt;BR /&gt;A.*,B.*&lt;BR /&gt;from&amp;nbsp; A left join B&lt;BR /&gt;on A.N1 = b.N2&lt;BR /&gt;;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 May 2019 10:23:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/left-join-variables-type/m-p/558572#M155905</guid>
      <dc:creator>Mirou</dc:creator>
      <dc:date>2019-05-14T10:23:44Z</dc:date>
    </item>
    <item>
      <title>Re: left join  variables type</title>
      <link>https://communities.sas.com/t5/SAS-Programming/left-join-variables-type/m-p/558574#M155906</link>
      <description>&lt;P&gt;You cannot fit 15 digits in a character variable with only 12 bytes. If you actually have numbers with 15 digits, these can never match.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please supply examples for your character and numeric values.&lt;/P&gt;</description>
      <pubDate>Tue, 14 May 2019 10:43:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/left-join-variables-type/m-p/558574#M155906</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-05-14T10:43:02Z</dc:date>
    </item>
    <item>
      <title>Re: left join  variables type</title>
      <link>https://communities.sas.com/t5/SAS-Programming/left-join-variables-type/m-p/558576#M155908</link>
      <description>&lt;P&gt;Actually N1 and N2 are codes to many&amp;nbsp; products, i need to join the two tables to recover&amp;nbsp; all the information related to the same product&lt;/P&gt;&lt;P&gt;example code N1: 111256897,111256875,111256999&lt;/P&gt;&lt;P&gt;N2:111256875,115252455&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 May 2019 10:53:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/left-join-variables-type/m-p/558576#M155908</guid>
      <dc:creator>Mirou</dc:creator>
      <dc:date>2019-05-14T10:53:08Z</dc:date>
    </item>
    <item>
      <title>Re: left join  variables type</title>
      <link>https://communities.sas.com/t5/SAS-Programming/left-join-variables-type/m-p/558586#M155909</link>
      <description>&lt;P&gt;Then you need to convert one of the columns so it fits the other. See this example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data n1;
input code :$12. a $;
datalines;
111256897 a
111256875 b
111256999 c
;
run;

data n2;
input code :12. b $;
datalines;
111256875 d
115252455 e
;
run;

proc sql;
create table want as
select coalesce(n1.code,left(put(n2.code,12.))) as code, n1.a, n2.b
from n1 full join n2
on (n1.code = left(put(n2.code,12.)));
quit;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;  code       a    b

111256875    b    d
111256897    a     
111256999    c     
115252455         e
&lt;/PRE&gt;
&lt;P&gt;You can see that the one match is found.&lt;/P&gt;</description>
      <pubDate>Tue, 14 May 2019 11:40:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/left-join-variables-type/m-p/558586#M155909</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-05-14T11:40:27Z</dc:date>
    </item>
    <item>
      <title>Re: left join  variables type</title>
      <link>https://communities.sas.com/t5/SAS-Programming/left-join-variables-type/m-p/558605#M155915</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/218252"&gt;@Mirou&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Actually N1 and N2 are codes to many&amp;nbsp; products, i need to join the two tables to recover&amp;nbsp; all the information related to the same product&lt;/P&gt;
&lt;P&gt;example code N1: 111256897,111256875,111256999&lt;/P&gt;
&lt;P&gt;N2:111256875,115252455&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If they are codes then they should be character strings. You will not be taking the mean of a code.&lt;/P&gt;
&lt;P&gt;You can use the PUT() function to convert numbers into character strings.&amp;nbsp; Make sure not to introduce leading spaces.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;charcode = put(numcode,12.-L);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But you also need to make sure that your codes do not supposed to include leading zeros.&amp;nbsp; In that case you could use the Z format.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;charcode = put(numcode,z12.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that you might need to go back to the source data for the dataset that has created the codes as numbers and re-read the source files as characters to fix some of the issues that could have been caused by reading the codes as numbers.&lt;/P&gt;</description>
      <pubDate>Tue, 14 May 2019 12:59:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/left-join-variables-type/m-p/558605#M155915</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-05-14T12:59:00Z</dc:date>
    </item>
    <item>
      <title>Re: left join  variables type</title>
      <link>https://communities.sas.com/t5/SAS-Programming/left-join-variables-type/m-p/558664#M155927</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/218252"&gt;@Mirou&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I need to join two sas tables using left join,&amp;nbsp; the problem is that&amp;nbsp;&lt;/P&gt;
&lt;P&gt;N1 type is 12$. and N2 is a numeric 15.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;i try to convert N2 to a character 15$. using a new variable N3 =put(N2,15$.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but sas couldn't find a matches between the two tables, that was confirmed by the full join,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;could you help me with that,&lt;/P&gt;
&lt;P&gt;thanks,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc SQL;&lt;BR /&gt;create table C as select&lt;BR /&gt;A.*,B.*&lt;BR /&gt;from&amp;nbsp; A left join B&lt;BR /&gt;on A.N1 = b.N2&lt;BR /&gt;;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;A couple of issues: Create character value from numeric using a numeric format with the Put statement: N3 =put(N2,15.)&lt;/P&gt;
&lt;P&gt;Second is any value that is less than 15 digits will have leading blanks. So if you try to match '12345' with '&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 12345' you do not get a match.&lt;/P&gt;
&lt;P&gt;There&amp;nbsp; are two ways to fix that. One is to use the -L option in the PUT function to left align the value so '12345&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ' is created or to use&lt;/P&gt;
&lt;P&gt;the Strip or Left functions to align the value.&lt;/P&gt;
&lt;PRE&gt;data junk;
   x = 12345;
   y = put(x,f15.);
   z = put(x,f15. -L);
   u = strip(put(x,f15.));
run;&lt;/PRE&gt;
&lt;P&gt;Use one the forms for Z or U above.&lt;/P&gt;</description>
      <pubDate>Tue, 14 May 2019 15:50:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/left-join-variables-type/m-p/558664#M155927</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-05-14T15:50:04Z</dc:date>
    </item>
  </channel>
</rss>

