<?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: multiple table merging in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/multiple-table-merging/m-p/576453#M163178</link>
    <description>&lt;P&gt;Maxim 3: Know Your Data.&lt;/P&gt;
&lt;P&gt;Maxim 3 implies that you also need to know relationships between datasets, as that is the absolutely necessary basis for writing correct merge or join code. If you find that you do not have a one-to-one or one-to-many relationship, but have to deal with a many-to-many relationship, you need to decide:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;do a cartesian join (that's what you get with SQL, as you experienced)&lt;/LI&gt;
&lt;LI&gt;create intermediary summary tables (for a data step one-to-one or one-to-many merge)&lt;/LI&gt;
&lt;LI&gt;use grouping and summing in SQL&lt;/LI&gt;
&lt;LI&gt;or is it possible to put the data side-by-side anyway without losing information (classic data step merge)&lt;/LI&gt;
&lt;/UL&gt;</description>
    <pubDate>Thu, 25 Jul 2019 06:03:31 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2019-07-25T06:03:31Z</dc:date>
    <item>
      <title>multiple table merging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-table-merging/m-p/576432#M163162</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;BR /&gt;
proc sql;
create table mr as
select
  z.gvkey,
  z.fyear,
  a.mr13,
  a.rawret13,
  b.mr16,
  b.rawret16,
  c.mr24,
  c.rawret24,
  d.mr25,
  d.rawret25,
  e.mr28,
  e.rawret28,
  f.mr37,
  f.rawret37,
  g.mr40,
  g.rawret40
from
esgprice z,
  mr13 a,
  mr16 b,
  mr24 c,
  mr25 d,
  mr28 e,
  mr37 f,
  mr40 g
where
z.gvkey = a.gvkey and
z.fyear  = a.fyear and
z.gvkey = b.gvkey and
z.fyear  = b.fyear and
z.gvkey = c.gvkey and
z.fyear  = c.fyear and
z.gvkey = d.gvkey and
z.fyear  = d.fyear and
z.gvkey = e.gvkey and
z.fyear  = e.fyear and
z.gvkey = f.gvkey and
z.fyear  = f.fyear and
z.gvkey = g.gvkey and
z.fyear  = g.fyear;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Hi all!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I referred to this link:&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Merge-Multiple-tables/td-p/384279" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Merge-Multiple-tables/td-p/384279&lt;/A&gt;&lt;/P&gt;&lt;P&gt;to merge 8 tables and, again, in trouble.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Instead of what I wanted, around 6000 values, I obtained more than a million values due to duplicates.&amp;nbsp;&lt;/P&gt;&lt;P&gt;It looks that I used many gvkey=gvkey and fyear=fyear. I thought SAS may consider them as group by FYEAR and GVKEY but didn't.&lt;/P&gt;&lt;P&gt;As I see in one table-on-one table merge I assumed that AND may mean each gvkey in each year. I just tried group by ~~, ~~;&lt;/P&gt;&lt;P&gt;Yes.&amp;nbsp; I got this error code;&amp;nbsp;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So... how can I get the result without duplicates? I simply want to have the outcome as I do with one table by one table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. I have a lot of variables in Z table and writing every single item in the above code is somewhat looking like dumb. I guess there must be a short cut to put all variables in my Z table. Do you know that kind of code?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Somehow I need to finish my summer project but after that I have to take some SAS class at Udemy or whatever online courses...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much for your help&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jul 2019 01:56:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-table-merging/m-p/576432#M163162</guid>
      <dc:creator>JKCho</dc:creator>
      <dc:date>2019-07-25T01:56:28Z</dc:date>
    </item>
    <item>
      <title>Re: multiple table merging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-table-merging/m-p/576434#M163164</link>
      <description>&lt;P&gt;Why are you using SQL if you just want to do a normal merge?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data mr;
  merge  mr13 mr16 mr24 mr25 mr28 mr37 mr40;
  by gvkey&amp;nbsp;fyear;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Jul 2019 02:21:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-table-merging/m-p/576434#M163164</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-25T02:21:17Z</dc:date>
    </item>
    <item>
      <title>Re: multiple table merging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-table-merging/m-p/576453#M163178</link>
      <description>&lt;P&gt;Maxim 3: Know Your Data.&lt;/P&gt;
&lt;P&gt;Maxim 3 implies that you also need to know relationships between datasets, as that is the absolutely necessary basis for writing correct merge or join code. If you find that you do not have a one-to-one or one-to-many relationship, but have to deal with a many-to-many relationship, you need to decide:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;do a cartesian join (that's what you get with SQL, as you experienced)&lt;/LI&gt;
&lt;LI&gt;create intermediary summary tables (for a data step one-to-one or one-to-many merge)&lt;/LI&gt;
&lt;LI&gt;use grouping and summing in SQL&lt;/LI&gt;
&lt;LI&gt;or is it possible to put the data side-by-side anyway without losing information (classic data step merge)&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Thu, 25 Jul 2019 06:03:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-table-merging/m-p/576453#M163178</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-07-25T06:03:31Z</dc:date>
    </item>
  </channel>
</rss>

