<?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 table by id in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/join-table-by-id/m-p/717177#M80132</link>
    <description>&lt;P&gt;There are at least a half dozen ways to do this.&lt;/P&gt;
&lt;P&gt;If you data sets are actually sorted by the Id and date and there are not any of the same dates in A and B then&lt;/P&gt;
&lt;PRE&gt;data want; 
   merge A 
         B
   ;
   by id date;
run;&lt;/PRE&gt;
&lt;P&gt;is about the simplest.&lt;/P&gt;
&lt;P&gt;If you have duplicates of Date for a given Id then you may want:&lt;/P&gt;
&lt;PRE&gt;data want;
   set A
        B
   ;
run;

proc sort data=want;
   by id date;
run;&lt;/PRE&gt;</description>
    <pubDate>Fri, 05 Feb 2021 19:01:50 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-02-05T19:01:50Z</dc:date>
    <item>
      <title>join table by id</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/join-table-by-id/m-p/717175#M80131</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to join table by id&lt;/P&gt;
&lt;P&gt;Table A&lt;/P&gt;
&lt;P&gt;id date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; price&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; 20170101&amp;nbsp; &amp;nbsp; 10&lt;/P&gt;
&lt;P&gt;1 20170102&amp;nbsp; &amp;nbsp; &amp;nbsp; 12&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; 20180401&amp;nbsp; &amp;nbsp; &amp;nbsp;8&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp;20180402&amp;nbsp; &amp;nbsp; 5&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Table B&lt;/P&gt;
&lt;P&gt;id date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; price&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; 20170103&amp;nbsp; &amp;nbsp; 15&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; 20180405&amp;nbsp; &amp;nbsp; &amp;nbsp;4&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;want A and B&lt;/P&gt;
&lt;P&gt;id date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; price&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; 20170101&amp;nbsp; &amp;nbsp; 10&lt;/P&gt;
&lt;P&gt;1 20170102&amp;nbsp; &amp;nbsp; &amp;nbsp; 12&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;1&amp;nbsp; 20170103&amp;nbsp; &amp;nbsp; 15&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; 20180401&amp;nbsp; &amp;nbsp; &amp;nbsp;8&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp;20180402&amp;nbsp; &amp;nbsp; 5&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;2&amp;nbsp; 20180405&amp;nbsp; &amp;nbsp; &amp;nbsp;4&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Feb 2021 18:56:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/join-table-by-id/m-p/717175#M80131</guid>
      <dc:creator>sasphd</dc:creator>
      <dc:date>2021-02-05T18:56:40Z</dc:date>
    </item>
    <item>
      <title>Re: join table by id</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/join-table-by-id/m-p/717177#M80132</link>
      <description>&lt;P&gt;There are at least a half dozen ways to do this.&lt;/P&gt;
&lt;P&gt;If you data sets are actually sorted by the Id and date and there are not any of the same dates in A and B then&lt;/P&gt;
&lt;PRE&gt;data want; 
   merge A 
         B
   ;
   by id date;
run;&lt;/PRE&gt;
&lt;P&gt;is about the simplest.&lt;/P&gt;
&lt;P&gt;If you have duplicates of Date for a given Id then you may want:&lt;/P&gt;
&lt;PRE&gt;data want;
   set A
        B
   ;
run;

proc sort data=want;
   by id date;
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 Feb 2021 19:01:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/join-table-by-id/m-p/717177#M80132</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-02-05T19:01:50Z</dc:date>
    </item>
    <item>
      <title>Re: join table by id</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/join-table-by-id/m-p/717178#M80133</link>
      <description>&lt;P&gt;This isn't a join, as far as I understand SQL notation and syntax.&amp;nbsp; This can be achieved in SQL using a UNION but it requires another pass to get the order correct.&amp;nbsp; But SAS can interleave the records; I was taught the term collate, I digress.&amp;nbsp; The datasets A and B I presume are properly sorted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set a b;
    by id date;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Feb 2021 19:05:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/join-table-by-id/m-p/717178#M80133</guid>
      <dc:creator>PhilC</dc:creator>
      <dc:date>2021-02-05T19:05:53Z</dc:date>
    </item>
  </channel>
</rss>

