<?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: SQL JOIN - one column twice in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/SQL-JOIN-one-column-twice/m-p/632608#M21106</link>
    <description>&lt;P&gt;Just replace the "and" in your condition with "or":&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
infile datalines dlm=',' dsd truncover;
input apple_name :$20. pear_name :$20. weight;
datalines;
Golden Smith,,300
,Gren Anjou,280
,,250
;

data have2;
infile datalines dlm=',' dsd truncover;
input fruit_index :$10. fruit_name :$20.;
datalines;
Apple,Golden Smith
Pear,Gren Anjou
;

proc sql;
create table want as
select a.*, b.fruit_index
from have1 a left join have2 b
on a.apple_name = b.fruit_name or a.pear_name = b.fruit_name;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 17 Mar 2020 09:59:43 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-03-17T09:59:43Z</dc:date>
    <item>
      <title>SQL JOIN - one column twice</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SQL-JOIN-one-column-twice/m-p/632597#M21098</link>
      <description>&lt;P&gt;Hi guys,&lt;BR /&gt;&lt;BR /&gt;I have two tables and I need to get info from one table to the second one, so I used JOIN. But I need to add index from one column from table #2 joined on two columns in table #1 (e.g.: I need to mark apples and pears as a fruit, fruit index is info from table #2, apple index is in column A in table #1 and pear index is in column B in table #1). Is it possible to do it? And is it possible to do it in one step?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Mar 2020 09:13:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SQL-JOIN-one-column-twice/m-p/632597#M21098</guid>
      <dc:creator>PM23</dc:creator>
      <dc:date>2020-03-17T09:13:26Z</dc:date>
    </item>
    <item>
      <title>Re: SQL JOIN - one column twice</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SQL-JOIN-one-column-twice/m-p/632598#M21099</link>
      <description>&lt;P&gt;Please show us your input data, preferably in data steps with datalines, so we can easily use it for testing.&lt;/P&gt;
&lt;P&gt;Also show the intended result.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Mar 2020 09:20:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SQL-JOIN-one-column-twice/m-p/632598#M21099</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-03-17T09:20:18Z</dc:date>
    </item>
    <item>
      <title>Re: SQL JOIN - one column twice</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SQL-JOIN-one-column-twice/m-p/632601#M21101</link>
      <description>&lt;P&gt;Let's say I have two tables:&lt;BR /&gt;&lt;BR /&gt;First one - columns Apple_name, Pear_name (empty, if it is apple and vice versa), Weight&lt;/P&gt;&lt;P&gt;Second one - columns Fruit_index, Name&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I tried:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;proc sql;
	create table test as
		select a.*, b.fruit_index
			from First_table a left join Second_table b 
				on a.Apple_name=b.Name and a.Pear_name=b.Name;
quit;&lt;/PRE&gt;&lt;P&gt;But it seems that just one part joined.&lt;BR /&gt;&lt;BR /&gt;Intended result:&lt;BR /&gt;First row - Apple_name: Golden Smith, Pear_name:., Weight: 300, Fruit_index: Apple&lt;BR /&gt;Second row - Apple_name:., Pear_name: Gren Anjou Weight: 280, Fruit_index: Pear&lt;BR /&gt;Third row - Apple_name:., Pear_name:., Weight: 250, Fruit Index:.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Mar 2020 09:41:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SQL-JOIN-one-column-twice/m-p/632601#M21101</guid>
      <dc:creator>PM23</dc:creator>
      <dc:date>2020-03-17T09:41:44Z</dc:date>
    </item>
    <item>
      <title>Re: SQL JOIN - one column twice</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SQL-JOIN-one-column-twice/m-p/632608#M21106</link>
      <description>&lt;P&gt;Just replace the "and" in your condition with "or":&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
infile datalines dlm=',' dsd truncover;
input apple_name :$20. pear_name :$20. weight;
datalines;
Golden Smith,,300
,Gren Anjou,280
,,250
;

data have2;
infile datalines dlm=',' dsd truncover;
input fruit_index :$10. fruit_name :$20.;
datalines;
Apple,Golden Smith
Pear,Gren Anjou
;

proc sql;
create table want as
select a.*, b.fruit_index
from have1 a left join have2 b
on a.apple_name = b.fruit_name or a.pear_name = b.fruit_name;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 17 Mar 2020 09:59:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SQL-JOIN-one-column-twice/m-p/632608#M21106</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-03-17T09:59:43Z</dc:date>
    </item>
    <item>
      <title>Re: SQL JOIN - one column twice</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SQL-JOIN-one-column-twice/m-p/632611#M21109</link>
      <description>&lt;P&gt;It was that simple! Thank you very much.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Mar 2020 10:36:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SQL-JOIN-one-column-twice/m-p/632611#M21109</guid>
      <dc:creator>PM23</dc:creator>
      <dc:date>2020-03-17T10:36:37Z</dc:date>
    </item>
  </channel>
</rss>

