<?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: how to eliminate the cartesian result in joins in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/how-to-eliminate-the-cartesian-result-in-joins/m-p/149691#M2526</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What would your expected output be for the above data?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 14 Dec 2014 18:19:34 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2014-12-14T18:19:34Z</dc:date>
    <item>
      <title>how to eliminate the cartesian result in joins</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/how-to-eliminate-the-cartesian-result-in-joins/m-p/149690#M2525</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;how to eliminate the cartesian result in joins if two datasets are having more than 1 record in 2 datasets (no chance to differentiate uniquely with the existed variables ).&lt;/P&gt;&lt;P&gt; For ex:&lt;/P&gt;&lt;P&gt; data a;&lt;/P&gt;&lt;P&gt; input pid age sex $;&lt;SPAN class="text_exposed_show"&gt;&lt;BR /&gt; cards;&lt;BR /&gt; 1 21 m&lt;BR /&gt; 1 22 f&lt;BR /&gt; 1 23 m&lt;BR /&gt; 2 34 f&lt;BR /&gt; 2 33 f&lt;BR /&gt; ;&lt;BR /&gt; data b;&lt;BR /&gt; input pid age Drug $;&lt;BR /&gt; cards;&lt;BR /&gt; 1 21 Placebo&lt;BR /&gt; 1 22 aceclo&lt;BR /&gt; 2 34 Placebo&lt;BR /&gt; 2 33 Diclofe&lt;BR /&gt; 2 34 notavailable&lt;BR /&gt; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="text_exposed_show"&gt;&lt;SPAN data-ft="{&amp;quot;tn&amp;quot;:&amp;quot;K&amp;quot;}" data-reactid=".56.1:3:1:$comment907105855974829_907112599307488:0.0.$right.0.$left.0.0.1:$comment-body"&gt;&lt;SPAN class="UFICommentBody" data-reactid=".56.1:3:1:$comment907105855974829_907112599307488:0.0.$right.0.$left.0.0.1:$comment-body.0"&gt;&lt;SPAN data-reactid=".56.1:3:1:$comment907105855974829_907112599307488:0.0.$right.0.$left.0.0.1:$comment-body.0.$end:0:$0:0"&gt;kindly note that ,in the output Need to report all records without missing from either of the datasets.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 14 Dec 2014 13:24:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/how-to-eliminate-the-cartesian-result-in-joins/m-p/149690#M2525</guid>
      <dc:creator>venkatnaveen</dc:creator>
      <dc:date>2014-12-14T13:24:25Z</dc:date>
    </item>
    <item>
      <title>Re: how to eliminate the cartesian result in joins</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/how-to-eliminate-the-cartesian-result-in-joins/m-p/149691#M2526</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What would your expected output be for the above data?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 14 Dec 2014 18:19:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/how-to-eliminate-the-cartesian-result-in-joins/m-p/149691#M2526</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-12-14T18:19:34Z</dc:date>
    </item>
    <item>
      <title>Re: how to eliminate the cartesian result in joins</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/how-to-eliminate-the-cartesian-result-in-joins/m-p/149692#M2527</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A proc sql with joins on id and age should work as long as there are no null values in id and age.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; CREATE TABLE want AS &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; SELECT t1.pid, &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; t1.age, &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; t1.sex, &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; t2.Drug&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM A t1&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; FULL JOIN B t2 ON (t1.pid = t2.pid) AND (t1.age = t2.age);&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 14 Dec 2014 18:33:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/how-to-eliminate-the-cartesian-result-in-joins/m-p/149692#M2527</guid>
      <dc:creator>sas_null_</dc:creator>
      <dc:date>2014-12-14T18:33:38Z</dc:date>
    </item>
    <item>
      <title>Re: how to eliminate the cartesian result in joins</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/how-to-eliminate-the-cartesian-result-in-joins/m-p/149693#M2528</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;To "&lt;EM style="font-size: 12.8000001907349px; background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;report all records without missing from either of the datasets&lt;/EM&gt;", you need a &lt;STRONG&gt;full join&lt;/STRONG&gt; and the &lt;STRONG&gt;coalesce&lt;/STRONG&gt; function on the joined fields: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data a;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;input pid age Sex $;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;cards;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1 21 m&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1 22 f&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1 23 m&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;2 34 f&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;2 33 f&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data b;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;length Drug $16;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;input pid age Drug $;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;cards;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1 21 Placebo&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1 22 aceclo&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;2 34 Placebo&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;2 33 Diclofe&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;2 34 notavailable&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;3 27 newDrug&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc sql;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;select &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; coalesce(a.pid, b.pid) as Pid,&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; coalesce(a.age, b.age) as Age,&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.sex,&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; b.drug&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;from &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; a full join&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; b on a.pid=b.pid and a.age=b.age;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In a case like above where the joined fields have the same names in both tables and all non-matching fields have distinct names, you can also use a &lt;STRONG&gt;natural full join&lt;/STRONG&gt; and save some typing:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc sql;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;select *&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;from a natural full join b;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note, I added a non-matching record in table b to show the full effect.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Dec 2014 02:50:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/how-to-eliminate-the-cartesian-result-in-joins/m-p/149693#M2528</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2014-12-15T02:50:51Z</dc:date>
    </item>
  </channel>
</rss>

