<?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 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Left-Join/m-p/386551#M277227</link>
    <description>&lt;P&gt;Can you state the rules by which matching should happen (and also which things won't match)? If so, then the code could be written. But we can't write code without that information.&lt;/P&gt;</description>
    <pubDate>Wed, 09 Aug 2017 11:06:57 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2017-08-09T11:06:57Z</dc:date>
    <item>
      <title>Left Join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Left-Join/m-p/386550#M277226</link>
      <description>&lt;P&gt;&lt;BR /&gt;Hi SAS Experts,&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;I have two tables a and b, both of them have common variables "Common_var" and "area", I want to bring all the records from table&lt;BR /&gt;"a" and matchings from table "b", it should match on both common variables "common_var" and "area", but the problem is 'area' in b table is not exactly matching with area in a table. Is there is anyway to get the below result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data a;&lt;BR /&gt;input area$ marks common_var$;&lt;BR /&gt;datalines;&lt;BR /&gt;abc 20 a&lt;BR /&gt;abc 30 a&lt;BR /&gt;bca 10 a&lt;BR /&gt;bca 20 a&lt;BR /&gt;vcv 19 a&lt;BR /&gt;fgf 30 a&lt;BR /&gt;ffg 49 a&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data b;&lt;BR /&gt;input area$ year subj$ common_var$;&lt;BR /&gt;datalines;&lt;BR /&gt;ab 2015 maths a&lt;BR /&gt;bc 2016 science a&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;result&lt;BR /&gt;area marks common_var year subj&lt;BR /&gt;abc 20 a 2015 maths&lt;BR /&gt;abc 30 a 2015 maths&lt;BR /&gt;bca 10 a 2016 science&lt;BR /&gt;bca 20 a 2016 science&lt;BR /&gt;vcv 19 a&lt;BR /&gt;fgf 30 a&lt;BR /&gt;ffg 49 a&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks &amp;amp; regards,&lt;/P&gt;
&lt;P&gt;Sanjay&lt;/P&gt;</description>
      <pubDate>Wed, 09 Aug 2017 11:04:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Left-Join/m-p/386550#M277226</guid>
      <dc:creator>sanjay1</dc:creator>
      <dc:date>2017-08-09T11:04:34Z</dc:date>
    </item>
    <item>
      <title>Re: Left Join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Left-Join/m-p/386551#M277227</link>
      <description>&lt;P&gt;Can you state the rules by which matching should happen (and also which things won't match)? If so, then the code could be written. But we can't write code without that information.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Aug 2017 11:06:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Left-Join/m-p/386551#M277227</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-08-09T11:06:57Z</dc:date>
    </item>
    <item>
      <title>Re: Left Join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Left-Join/m-p/386555#M277228</link>
      <description>&lt;P&gt;Hi PaigeMiller,&lt;BR /&gt;&lt;BR /&gt;Area(Abc and bca) and Common_var In table "A" should match with area (ab,bc) and common_var in B.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Aug 2017 11:06:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Left-Join/m-p/386555#M277228</guid>
      <dc:creator>sanjay1</dc:creator>
      <dc:date>2017-08-09T11:06:35Z</dc:date>
    </item>
    <item>
      <title>Re: Left Join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Left-Join/m-p/386556#M277229</link>
      <description>&lt;P&gt;Is area in dataset b of a fixed length (less than area in dataset a), or could it be of equal length to area in dataset a?&lt;/P&gt;</description>
      <pubDate>Wed, 09 Aug 2017 11:06:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Left-Join/m-p/386556#M277229</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-08-09T11:06:19Z</dc:date>
    </item>
    <item>
      <title>Re: Left Join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Left-Join/m-p/386559#M277230</link>
      <description>&lt;P&gt;It is less than area in dataset a&lt;/P&gt;</description>
      <pubDate>Wed, 09 Aug 2017 11:11:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Left-Join/m-p/386559#M277230</guid>
      <dc:creator>sanjay1</dc:creator>
      <dc:date>2017-08-09T11:11:14Z</dc:date>
    </item>
    <item>
      <title>Re: Left Join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Left-Join/m-p/386564#M277231</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/91059"&gt;@sanjay1&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;It is less than area in dataset a&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Then take account of that in the condition for the join:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select
  a.*,
  b.area as area_b,
  b.year,
  b.subj
from
  a left join
  b
  on substr(a.area,1,length(b.area)) = b.area
  and a.common_var = b.common_var
;
quit;

proc print data=want noobs;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;                 common_
area    marks      var      area_b    year     subj

abc       20        a         ab      2015    maths  
abc       30        a         ab      2015    maths  
bca       10        a         bc      2016    science
bca       20        a         bc      2016    science
fgf       30        a                    .           
vcv       19        a                    .           
ffg       49        a                    .           
&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 Aug 2017 11:17:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Left-Join/m-p/386564#M277231</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-08-09T11:17:56Z</dc:date>
    </item>
    <item>
      <title>Re: Left Join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Left-Join/m-p/386599#M277232</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
input area$ marks common_var$;
datalines;
abc 20 a
abc 30 a
bca 10 a
bca 20 a
vcv 19 a
fgf 30 a
ffg 49 a
;
run;
 
data b;
input area$ year subj$ common_var$;
datalines;
ab 2015 maths a
bc 2016 science a
;
run;

proc sql;
select a.*,year,subj
 from a left join b 
  on a.common_var=b.common_var and
     b.area eqt a.area;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 Aug 2017 12:49:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Left-Join/m-p/386599#M277232</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-08-09T12:49:43Z</dc:date>
    </item>
  </channel>
</rss>

