<?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 different columns in same table. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Joining-on-different-columns-in-same-table/m-p/416298#M102195</link>
    <description>&lt;P&gt;And what have you tried?&amp;nbsp; We are not here to do it all for your.&amp;nbsp; Some starting points:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Condition 1:&lt;/P&gt;
&lt;P&gt;If dataset 'PK' contains sub_id=0 then join should on dept_id&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;from  KK A
left join (select * from PK where index(put(SUB_ID,best.),"0") &amp;gt; 0) B
on     A.DEPT_ID=B.DEPT_ID;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;condition 2:&lt;/P&gt;
&lt;P&gt;if dataset 'PK' sub_id != 0 then join should on sub_id&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;from  KK A
left join (select * from PK where SUB_ID ne 0) B
on     A.SUB_ID=B.SUB_ID;
&lt;/PRE&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;P&gt;&amp;nbsp;&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;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 27 Nov 2017 09:42:37 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-11-27T09:42:37Z</dc:date>
    <item>
      <title>Joining on different columns in same table.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Joining-on-different-columns-in-same-table/m-p/416295#M102194</link>
      <description>&lt;P&gt;I have this data&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data KK;&lt;BR /&gt;input sub_id complain_id dept_id;&lt;BR /&gt;datalines;&lt;BR /&gt;101 1 11&lt;BR /&gt;102 2 12&lt;BR /&gt;104 4 13&lt;BR /&gt;105 5 15&lt;BR /&gt;107 7 14&lt;BR /&gt;108 8 16&lt;BR /&gt;109 9 17&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data PK;&lt;BR /&gt;input sub_id dept_id duration;&lt;BR /&gt;datalines;&lt;BR /&gt;104 13 10&lt;BR /&gt;101 11 20&lt;BR /&gt;102 12 30&lt;BR /&gt;107 14 40&lt;BR /&gt;105 19 50&lt;BR /&gt;0 14 100&lt;BR /&gt;0 13 60&lt;BR /&gt;0 15 70&lt;BR /&gt;0 11 80&lt;BR /&gt;0 12 90&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and now I want to join these two datasets with two diff conditions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Condition 1:&lt;/P&gt;&lt;P&gt;If dataset 'PK' contains sub_id=0 then join should on dept_id&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;condition 2:&lt;/P&gt;&lt;P&gt;if dataset 'PK' sub_id != 0 then join should on sub_id&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If any solution you have then please share the code for this query.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2017 09:34:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Joining-on-different-columns-in-same-table/m-p/416295#M102194</guid>
      <dc:creator>india2016</dc:creator>
      <dc:date>2017-11-27T09:34:48Z</dc:date>
    </item>
    <item>
      <title>Re: Joining on different columns in same table.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Joining-on-different-columns-in-same-table/m-p/416298#M102195</link>
      <description>&lt;P&gt;And what have you tried?&amp;nbsp; We are not here to do it all for your.&amp;nbsp; Some starting points:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Condition 1:&lt;/P&gt;
&lt;P&gt;If dataset 'PK' contains sub_id=0 then join should on dept_id&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;from  KK A
left join (select * from PK where index(put(SUB_ID,best.),"0") &amp;gt; 0) B
on     A.DEPT_ID=B.DEPT_ID;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;condition 2:&lt;/P&gt;
&lt;P&gt;if dataset 'PK' sub_id != 0 then join should on sub_id&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;from  KK A
left join (select * from PK where SUB_ID ne 0) B
on     A.SUB_ID=B.SUB_ID;
&lt;/PRE&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;P&gt;&amp;nbsp;&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;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2017 09:42:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Joining-on-different-columns-in-same-table/m-p/416298#M102195</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-11-27T09:42:37Z</dc:date>
    </item>
    <item>
      <title>Re: Joining on different columns in same table.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Joining-on-different-columns-in-same-table/m-p/416302#M102196</link>
      <description>&lt;P&gt;I'd follow my maxim 29 (when in doubt, use brute force).&lt;/P&gt;
&lt;P&gt;- split PK into two datasets, along sub_id = 0 or not; drop sub_id or dept_id, respectively&lt;/P&gt;
&lt;P&gt;- sort those two dataset along their remaining id's&lt;/P&gt;
&lt;P&gt;- sort kk along dept_id, and merge with the respective subset&lt;/P&gt;
&lt;P&gt;- sort result along sub_id, and merge along sub_id with the other subset&lt;/P&gt;
&lt;P&gt;- sort result along complain_id to get the original order&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2017 09:52:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Joining-on-different-columns-in-same-table/m-p/416302#M102196</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-11-27T09:52:21Z</dc:date>
    </item>
    <item>
      <title>Re: Joining on different columns in same table.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Joining-on-different-columns-in-same-table/m-p/416304#M102197</link>
      <description>&lt;P&gt;Yes, I already tried this code separately(e.g. Split the data and join on different conditions) but now I want the respective 'Duration' in output in single code so I am trying&amp;nbsp;to consolidate&amp;nbsp;in the single code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My final table output should be like this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Complain_ID sub_ID dept_id Duration&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 101&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;11&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20&lt;/P&gt;&lt;P&gt;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;90&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;is it possible in single code?&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;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2017 09:54:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Joining-on-different-columns-in-same-table/m-p/416304#M102197</guid>
      <dc:creator>india2016</dc:creator>
      <dc:date>2017-11-27T09:54:45Z</dc:date>
    </item>
  </channel>
</rss>

