<?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 with Enterprise Guide in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Left-Join-with-Enterprise-Guide/m-p/39656#M4749</link>
    <description>Thank you all for your help!</description>
    <pubDate>Wed, 13 Jan 2010 18:54:46 GMT</pubDate>
    <dc:creator>psusudzi92</dc:creator>
    <dc:date>2010-01-13T18:54:46Z</dc:date>
    <item>
      <title>Left Join with Enterprise Guide</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Left-Join-with-Enterprise-Guide/m-p/39649#M4742</link>
      <description>I am trying to put together some output displaying all subjects in the database with their medications and adverse events side by side, e.g. Subj, Med, AE. I need to use a join to pull the data from the CM and AE tables so I used the SUBJID in a left join (thinking this is correct).&lt;BR /&gt;
&lt;BR /&gt;
The problem is that in the output, I am getting a mashup of every med lnked with every AE for each subject, which appears to be a cartesian join and not what I was expecting in the output.&lt;BR /&gt;
&lt;BR /&gt;
The code is below, any suggestions in correcting this? I've plyed around with various other joins that Enterprise Guide allows but all seem to come up with a massive cartesian output.&lt;BR /&gt;
&lt;BR /&gt;
PROC SQL;&lt;BR /&gt;
   CREATE TABLE SASUSER.QUERY_FOR_CM_SAS7BDAT_0002 AS &lt;BR /&gt;
   SELECT t1.SUBJID, &lt;BR /&gt;
          t1.CMTRT, &lt;BR /&gt;
          t2.AETRT&lt;BR /&gt;
      FROM EC100045.cm AS t1 LEFT JOIN EC100047.ae AS t2 ON (t1.SUBJID = t2.SUBJID)&lt;BR /&gt;
      WHERE t1.SUBJID = '201-008' AND t1.CMTRT NOT = '' AND t2.AETRT NOT = ''&lt;BR /&gt;
      ORDER BY t1.SUBJID, t1.CMTRT;&lt;BR /&gt;
QUIT;</description>
      <pubDate>Tue, 12 Jan 2010 19:17:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Left-Join-with-Enterprise-Guide/m-p/39649#M4742</guid>
      <dc:creator>psusudzi92</dc:creator>
      <dc:date>2010-01-12T19:17:21Z</dc:date>
    </item>
    <item>
      <title>Re: Left Join with Enterprise Guide</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Left-Join-with-Enterprise-Guide/m-p/39650#M4743</link>
      <description>To further clarify, here are the two example tables and how I'd like to see the output. I now believe this should be an outer join but again I seem to keep getting cartesian output.&lt;BR /&gt;
&lt;BR /&gt;
CM&lt;BR /&gt;
subjid	cmtrt&lt;BR /&gt;
001	        ASIPIRIN&lt;BR /&gt;
001	        ZOFRAN&lt;BR /&gt;
002	        DIGOXIN&lt;BR /&gt;
002	        CARDIZEM&lt;BR /&gt;
&lt;BR /&gt;
AE&lt;BR /&gt;
subjid	aetrt&lt;BR /&gt;
001	        HEADACHE&lt;BR /&gt;
001	        NAUSEA&lt;BR /&gt;
002	        VOMITING&lt;BR /&gt;
003	        INDIGESTION&lt;BR /&gt;
&lt;BR /&gt;
Desired output:&lt;BR /&gt;
subjid	cmtrt	          aetrt&lt;BR /&gt;
001	        ASPIRIN	  HEADACHE&lt;BR /&gt;
001	        ZOFRAN	  NAUSEA&lt;BR /&gt;
002	        DIGOXIN	  VOMITING&lt;BR /&gt;
002	        CARDIZEM (null)&lt;BR /&gt;
003	        (null)	          INDIGESTION</description>
      <pubDate>Tue, 12 Jan 2010 20:27:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Left-Join-with-Enterprise-Guide/m-p/39650#M4743</guid>
      <dc:creator>psusudzi92</dc:creator>
      <dc:date>2010-01-12T20:27:07Z</dc:date>
    </item>
    <item>
      <title>Re: Left Join with Enterprise Guide</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Left-Join-with-Enterprise-Guide/m-p/39651#M4744</link>
      <description>What associates Asprin with Headache?  You must have some ID to add to your join or you will get a cartesian join.</description>
      <pubDate>Tue, 12 Jan 2010 20:43:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Left-Join-with-Enterprise-Guide/m-p/39651#M4744</guid>
      <dc:creator>Flip</dc:creator>
      <dc:date>2010-01-12T20:43:21Z</dc:date>
    </item>
    <item>
      <title>Re: Left Join with Enterprise Guide</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Left-Join-with-Enterprise-Guide/m-p/39652#M4745</link>
      <description>So you're saying I need to add something else other than joining on the SUBJID?&lt;BR /&gt;
&lt;BR /&gt;
It really doesn't matter to me how the AEs get linked to the meds, I just wanted to produce a list that displayed the results for each subject from both tables.</description>
      <pubDate>Tue, 12 Jan 2010 21:29:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Left-Join-with-Enterprise-Guide/m-p/39652#M4745</guid>
      <dc:creator>psusudzi92</dc:creator>
      <dc:date>2010-01-12T21:29:59Z</dc:date>
    </item>
    <item>
      <title>Re: Left Join with Enterprise Guide</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Left-Join-with-Enterprise-Guide/m-p/39653#M4746</link>
      <description>PROC SQL did what you asked it to do.  To get the dataset you want with that data, you are going to have to code it with a DATA step.  To use PROC SQL, you will need to add a 'row' number in addition to the subject ID to use in the LEFT JOIN.</description>
      <pubDate>Wed, 13 Jan 2010 03:16:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Left-Join-with-Enterprise-Guide/m-p/39653#M4746</guid>
      <dc:creator>Doc_Duke</dc:creator>
      <dc:date>2010-01-13T03:16:28Z</dc:date>
    </item>
    <item>
      <title>Re: Left Join with Enterprise Guide</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Left-Join-with-Enterprise-Guide/m-p/39654#M4747</link>
      <description>As my father in law would say, PROC SQL in this case is doomed as doomed can be. You're talking about a many-to-many combination, which for PROC SQL always means an internal cartesian product.&lt;BR /&gt;
&lt;BR /&gt;
As Doc suggested, you could do this with DATA step code although you'd have to really know what you're doing to come up with a way to get 002 CARDIZEM (null) instead of 002 CARDIZEM VOMITING.&lt;BR /&gt;
&lt;BR /&gt;
One alternative if the data is small: you could go ahead with the Cartesian product, then on the back end use a sort data task with no duplicates based on the values of subjid cmtrt. Note this ability is only built into the sort data task in EG 4.2 -- in previous versions, you'd have to manually add the NODUPKEY option to the code yourself. This still doesn't get exactly what you want, in that you would see 002 CARDIZEM VOMITING instead of 002 CARDIZEM (null). And if your data is large and/or in a database, your system administrator / database administrator is going to kill me for even mentioning this. IT IS MASSIVELY INEFFICIENT!! You've been warned. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Wed, 13 Jan 2010 14:41:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Left-Join-with-Enterprise-Guide/m-p/39654#M4747</guid>
      <dc:creator>RichardH_sas</dc:creator>
      <dc:date>2010-01-13T14:41:20Z</dc:date>
    </item>
    <item>
      <title>Re: Left Join with Enterprise Guide</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Left-Join-with-Enterprise-Guide/m-p/39655#M4748</link>
      <description>In EG you would need to do :&lt;BR /&gt;
&lt;BR /&gt;
data CM;&lt;BR /&gt;
input subjid $ cmtrt $;&lt;BR /&gt;
cards;&lt;BR /&gt;
001 ASIPIRIN&lt;BR /&gt;
001 ZOFRAN&lt;BR /&gt;
002 DIGOXIN&lt;BR /&gt;
002 CARDIZEM&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data AE;&lt;BR /&gt;
input subjid $ aetrt $;&lt;BR /&gt;
cards;&lt;BR /&gt;
001 HEADACHE&lt;BR /&gt;
001 NAUSEA&lt;BR /&gt;
002 VOMITING&lt;BR /&gt;
003 INDIGESTION&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sort data = cm;&lt;BR /&gt;
by subjid;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sort data = ae;&lt;BR /&gt;
by subjid;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data cm;&lt;BR /&gt;
set cm;&lt;BR /&gt;
by subjid;&lt;BR /&gt;
if first.subjid then cnt = 0;&lt;BR /&gt;
cnt + 1;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data ae;&lt;BR /&gt;
set ae;&lt;BR /&gt;
by subjid;&lt;BR /&gt;
if first.subjid then cnt = 0;&lt;BR /&gt;
cnt + 1;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
to get an identifyer on each row.&lt;BR /&gt;
Do an OUTER join to get the matching (on subjid and cnt)&lt;BR /&gt;
create a calculated column for SubjID  "coalescec(CM.subjid ,AE.subjid )"</description>
      <pubDate>Wed, 13 Jan 2010 14:56:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Left-Join-with-Enterprise-Guide/m-p/39655#M4748</guid>
      <dc:creator>Flip</dc:creator>
      <dc:date>2010-01-13T14:56:34Z</dc:date>
    </item>
    <item>
      <title>Re: Left Join with Enterprise Guide</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Left-Join-with-Enterprise-Guide/m-p/39656#M4749</link>
      <description>Thank you all for your help!</description>
      <pubDate>Wed, 13 Jan 2010 18:54:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Left-Join-with-Enterprise-Guide/m-p/39656#M4749</guid>
      <dc:creator>psusudzi92</dc:creator>
      <dc:date>2010-01-13T18:54:46Z</dc:date>
    </item>
  </channel>
</rss>

