<?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: Join tables and drop observations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Join-tables-and-drop-observations/m-p/233182#M42570</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;SQL&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;CREATE&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;TABLE&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; ENC_Join &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;AS&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;SELECT&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; a.patID a.encdate1&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;FROM&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; Caper.OBS_12ND &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;as&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; A&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;left&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;join&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; caper.encounterdate &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;as&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; b&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;on&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;(a.patID = b.patID and a.encdate1= b.encdate1);&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;quit&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is the error I'm getting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1057 PROC SQL;&lt;/P&gt;
&lt;P&gt;1058 CREATE TABLE&amp;nbsp; ENC_Join AS&lt;/P&gt;
&lt;P&gt;1059 SELECT a.patID, a.encdate1&lt;/P&gt;
&lt;P&gt;1060 FROM Caper.OBS_12ND as A&lt;/P&gt;
&lt;P&gt;1061 left join caper.encounterdate as b&lt;/P&gt;
&lt;P&gt;1062 on(a.patID = b.patID and a.encdate1= b.encdate1);&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;ERROR: Sort initialization failure.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can I resolve this error? Thanks!&lt;/P&gt;</description>
    <pubDate>Wed, 04 Nov 2015 21:23:06 GMT</pubDate>
    <dc:creator>jenim514</dc:creator>
    <dc:date>2015-11-04T21:23:06Z</dc:date>
    <item>
      <title>Join tables and drop observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-tables-and-drop-observations/m-p/233151#M42557</link>
      <description>&lt;P&gt;Hi!&amp;nbsp; I need to join two tables by PatientID and EncDate from table A to the matching PatientID and EncDate in table B and remove all other observations in table B that are not matched to PatientID and EncDate in table A.&amp;nbsp;&amp;nbsp;&amp;nbsp; SHould I rename variables in table B and then join?&amp;nbsp; If so, what type of join would I use?&amp;nbsp; This should be a&amp;nbsp; side by side join.&amp;nbsp; Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Nov 2015 19:44:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-tables-and-drop-observations/m-p/233151#M42557</guid>
      <dc:creator>jenim514</dc:creator>
      <dc:date>2015-11-04T19:44:30Z</dc:date>
    </item>
    <item>
      <title>Re: Join tables and drop observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-tables-and-drop-observations/m-p/233153#M42558</link>
      <description>&lt;P&gt;If I'm understanding this correctly, this is just a left join in SQL, i.e.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
  CREATE TABLE WANT AS
    SELECT A.*
    FROM HAVEA A
        LEFT JOIN HAVEB B
          ON (A.PATIENTID = B.PATIENTID AND A.ENCDATE = B.ENCDATE);
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This would keep all columns in dataset HAVEA. If you wanted to pull columns from HAVEB as well, you would just need to add them to the select statment.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Nov 2015 19:51:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-tables-and-drop-observations/m-p/233153#M42558</guid>
      <dc:creator>JoshB</dc:creator>
      <dc:date>2015-11-04T19:51:14Z</dc:date>
    </item>
    <item>
      <title>Re: Join tables and drop observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-tables-and-drop-observations/m-p/233154#M42559</link>
      <description>&lt;P&gt;As a side note, I had&amp;nbsp;&lt;A title="SQL Joins" href="http://www.securesolutions.no/wp-content/uploads/2014/07/joins-1.jpg" target="_blank"&gt;this&lt;/A&gt;&amp;nbsp;printed out and hanging on my office wall when I began using sql/PROC SQL. I thought it was a nice visual reminder.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Nov 2015 19:53:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-tables-and-drop-observations/m-p/233154#M42559</guid>
      <dc:creator>JoshB</dc:creator>
      <dc:date>2015-11-04T19:53:41Z</dc:date>
    </item>
    <item>
      <title>Re: Join tables and drop observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-tables-and-drop-observations/m-p/233155#M42560</link>
      <description>&lt;P&gt;Hi, thank you.&amp;nbsp; What if i wanted to just select two columns in table A (PatiendID and EncDate)&amp;nbsp;to merge with all columns in B (which are 100+)?&lt;/P&gt;</description>
      <pubDate>Wed, 04 Nov 2015 19:54:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-tables-and-drop-observations/m-p/233155#M42560</guid>
      <dc:creator>jenim514</dc:creator>
      <dc:date>2015-11-04T19:54:33Z</dc:date>
    </item>
    <item>
      <title>Re: Join tables and drop observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-tables-and-drop-observations/m-p/233157#M42561</link>
      <description>&lt;P&gt;I haven't personally tried this way before, but assuming the two columns you want from A are on A and B (as they would need to be for the join to work this way in the first place) you should in theory be able to just change the select statement to&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;SELECT B.*&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The FROM table (A) is still going to be the determinant of what to keep, given that you are left joining B. (untested, but this is what I would expect the behavior to be).&lt;/P&gt;</description>
      <pubDate>Wed, 04 Nov 2015 19:58:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-tables-and-drop-observations/m-p/233157#M42561</guid>
      <dc:creator>JoshB</dc:creator>
      <dc:date>2015-11-04T19:58:18Z</dc:date>
    </item>
    <item>
      <title>Re: Join tables and drop observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-tables-and-drop-observations/m-p/233182#M42570</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;SQL&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;CREATE&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;TABLE&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; ENC_Join &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;AS&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;SELECT&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; a.patID a.encdate1&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;FROM&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; Caper.OBS_12ND &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;as&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; A&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;left&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;join&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; caper.encounterdate &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;as&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; b&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;on&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;(a.patID = b.patID and a.encdate1= b.encdate1);&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;quit&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is the error I'm getting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1057 PROC SQL;&lt;/P&gt;
&lt;P&gt;1058 CREATE TABLE&amp;nbsp; ENC_Join AS&lt;/P&gt;
&lt;P&gt;1059 SELECT a.patID, a.encdate1&lt;/P&gt;
&lt;P&gt;1060 FROM Caper.OBS_12ND as A&lt;/P&gt;
&lt;P&gt;1061 left join caper.encounterdate as b&lt;/P&gt;
&lt;P&gt;1062 on(a.patID = b.patID and a.encdate1= b.encdate1);&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;ERROR: Sort initialization failure.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can I resolve this error? Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 04 Nov 2015 21:23:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-tables-and-drop-observations/m-p/233182#M42570</guid>
      <dc:creator>jenim514</dc:creator>
      <dc:date>2015-11-04T21:23:06Z</dc:date>
    </item>
    <item>
      <title>Re: Join tables and drop observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-tables-and-drop-observations/m-p/233183#M42571</link>
      <description>&lt;P&gt;I think you were missing a ", " between a.patID and a.encDate1 ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
  CREATE TABLE ENC_Join AS
  SELECT a.patID&lt;FONT color="#FF0000"&gt;,&lt;/FONT&gt; a.encdate1
  FROM Caper.OBS_12ND as A
  left join caper.encounterdate as b
    on(a.patID = b.patID and a.encdate1= b.encdate1);
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you still get&amp;nbsp;the error "Sort initialization failure", you might want to: (1) adjust memsize, or (2) add a "DISTINCT" in order to limit duplicate row output. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
  CREATE TABLE ENC_Join AS
  SELECT &lt;FONT color="#FF0000"&gt;DISTINCT&lt;/FONT&gt; a.patID, a.encdate1
  FROM Caper.OBS_12ND as A
  left join caper.encounterdate as b
    on(a.patID = b.patID and a.encdate1= b.encdate1);
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Nov 2015 21:39:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-tables-and-drop-observations/m-p/233183#M42571</guid>
      <dc:creator>hbi</dc:creator>
      <dc:date>2015-11-04T21:39:24Z</dc:date>
    </item>
  </channel>
</rss>

