<?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: Table merging question in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Table-merging-question/m-p/682317#M79496</link>
    <description>I think thats it.  its a one to many merge.  What do you suggest as the best way to accomplish this?</description>
    <pubDate>Tue, 08 Sep 2020 17:02:32 GMT</pubDate>
    <dc:creator>SannaSanna</dc:creator>
    <dc:date>2020-09-08T17:02:32Z</dc:date>
    <item>
      <title>Table merging question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Table-merging-question/m-p/682294#M79494</link>
      <description>&lt;P&gt;Hello!!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have two large tables I am trying to merge. Table 1 is called services and table 2 is customers.&amp;nbsp; I used the data step merge below and it appears that i am missing some records.&amp;nbsp; There can be multiple customers tied to the same service using the 'merge by unitA' but it seems that the code is picking and merging only on the first instance and missing subsequent customer records which should also be matched too but is missing- this is technically working but I am missing customer records.&amp;nbsp; Can this be correct?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA YFYS YFNS NFYS;&lt;BR /&gt;MERGE Service1(in=a) customer1(in=b); by unitA; &lt;BR /&gt;IF A AND B THEN OUTPUT YFYS; &lt;BR /&gt;IF A=1 AND B=0 THEN OUTPUT YFNS; &lt;BR /&gt;IF A=0 AND B=1 THEN OUTPUT NFYS; RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Sep 2020 16:06:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Table-merging-question/m-p/682294#M79494</guid>
      <dc:creator>SannaSanna</dc:creator>
      <dc:date>2020-09-08T16:06:06Z</dc:date>
    </item>
    <item>
      <title>Re: Table merging question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Table-merging-question/m-p/682302#M79495</link>
      <description>&lt;P&gt;Example data of both input and the output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you multiple records with the same value of UnitA in both data sets then likely the data step merge is not what you want as it was not designed for a many-to-many merge.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Sep 2020 16:21:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Table-merging-question/m-p/682302#M79495</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-09-08T16:21:01Z</dc:date>
    </item>
    <item>
      <title>Re: Table merging question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Table-merging-question/m-p/682317#M79496</link>
      <description>I think thats it.  its a one to many merge.  What do you suggest as the best way to accomplish this?</description>
      <pubDate>Tue, 08 Sep 2020 17:02:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Table-merging-question/m-p/682317#M79496</guid>
      <dc:creator>SannaSanna</dc:creator>
      <dc:date>2020-09-08T17:02:32Z</dc:date>
    </item>
    <item>
      <title>Re: Table merging question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Table-merging-question/m-p/682322#M79497</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12130"&gt;@SannaSanna&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I think thats it. its a one to many merge. What do you suggest as the best way to accomplish this?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If it really is a many-to-one merge (which way? many customers to a service -- or vice versa?), then the program you showed will accomplish what you apparently want.&amp;nbsp; You describe the problem as "I am missing some records".&amp;nbsp; That's not enough to make a diagnosis, let alone a prescription.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please show a sample of the data that become missing after running the merge statement.&amp;nbsp;&amp;nbsp; That's what &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt; was asking for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Help us help you.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Sep 2020 17:14:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Table-merging-question/m-p/682322#M79497</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-09-08T17:14:53Z</dc:date>
    </item>
    <item>
      <title>Re: Table merging question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Table-merging-question/m-p/682345#M79498</link>
      <description>&lt;P&gt;Hi.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below is a sample of the data.&amp;nbsp; I am merging by 'Rx'.&amp;nbsp; My output table (want) is missing the second row for jen.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="271"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD colspan="2" width="143"&gt;customer table&lt;/TD&gt;
&lt;TD width="64"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="64"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;customer table&lt;/TD&gt;
&lt;TD&gt;race&lt;/TD&gt;
&lt;TD&gt;Rx&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;jen&lt;/TD&gt;
&lt;TD&gt;w&lt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&gt;rob&lt;/TD&gt;
&lt;TD&gt;b&lt;/TD&gt;
&lt;TD&gt;d20&lt;/TD&gt;
&lt;TD&gt;rie&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Tue, 08 Sep 2020 18:11:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Table-merging-question/m-p/682345#M79498</guid>
      <dc:creator>SannaSanna</dc:creator>
      <dc:date>2020-09-08T18:11:42Z</dc:date>
    </item>
    <item>
      <title>Re: Table merging question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Table-merging-question/m-p/682396#M79499</link>
      <description>&lt;P&gt;That does not look like a one to one or one to many relationship.&amp;nbsp; Multiple people could have the same RX.&amp;nbsp; And at least some of the RX have multiple PH values (whatever that is).&amp;nbsp; Use SQL to combine them, it will perform a many to many join.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also learn how to share your data as simple data steps:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data customer;
  input id $ race $ Rx $;
cards;
jen w b12  
mik h xyy  
rob b d20  
;

data service;
  input Rx $ ph $;
cards; 
b12 wit    
b12 wan    
o18 chi    
xyy gon    
d20 rie
;

data want;
  input id $ race $ rx $ ph $;
cards;
jen w b12 wit
jen w b12 wan
mik h xyy gon
rob b d20 rie
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here is code to combine CUSTOMER and SERVICE based on match of RX.&amp;nbsp; I assumed you want all customers even if they do not have any matching service records so used a LEFT JOIN.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table try as
  select a.id,a.race,a.rx,b.ph
  from customer a
  left join service b
    on a.rx = b.rx 
  order by 1,2,3 
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;Obs    id     race    Rx     ph

 1     jen     w      b12    wit
 2     jen     w      b12    wan
 3     mik     h      xyy    gon
 4     rob     b      d20    rie&lt;/PRE&gt;</description>
      <pubDate>Tue, 08 Sep 2020 19:54:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Table-merging-question/m-p/682396#M79499</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-09-08T19:54:09Z</dc:date>
    </item>
    <item>
      <title>Re: Table merging question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Table-merging-question/m-p/682690#M79501</link>
      <description>Hi.  Thank you for your help!   My datasets are extremely large and having difficulty with resources and I just provided a brief example of the data.  Perhaps the set of data I provided was not a good example, but I have also used Proc SQL to tie the tables together and still missing records.  The merge is technically correct using the parameters to merge, however, there are missing join records.  Is it true that the SAS PDV runs through the data once and if successful moves on to the next record to merge?  What happens if one of my tables have some exact same row records (customer &amp;amp; lots of demographics) and the other table is a table of providers.   After merging by 'Rx' (providers Wit &amp;amp; Wan) serve the same customers and possibly on same day.  When merging (sorted by provider) it seems the merge is successful for the first sorted provider (Wan) but all those customer records did not merge with the second provider(Wit).  Is it that the SAS PDV moves on/finishes after initial succcessful merge even though there are second possible successful merge?  I'm stumped.</description>
      <pubDate>Wed, 09 Sep 2020 16:06:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Table-merging-question/m-p/682690#M79501</guid>
      <dc:creator>SannaSanna</dc:creator>
      <dc:date>2020-09-09T16:06:29Z</dc:date>
    </item>
    <item>
      <title>Re: Table merging question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Table-merging-question/m-p/682720#M79503</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12130"&gt;@SannaSanna&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's discuss the first problem you identify:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12130"&gt;@SannaSanna&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;... stuff deleted ...&lt;BR /&gt;but I have also used Proc SQL to tie the tables together and still missing records.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;"Missing records" is way too amibiguous to diagnose.&amp;nbsp; But from what you have shown us, any missing records are not due to size of the data sets.&amp;nbsp;&amp;nbsp;Please provide an explicit example of a record you expected in the result, but was missing.&amp;nbsp; And provide the initial records from which you expected it to be produced.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should be able to extract those records into a sample, and then quickly run both your SQL code and DATA step merge code that resulted in missing records.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Show us those codes, and the log file that went with them.&amp;nbsp;&amp;nbsp; Then diagnosis (and maybe prescription) is possible.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Sep 2020 17:32:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Table-merging-question/m-p/682720#M79503</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-09-09T17:32:12Z</dc:date>
    </item>
  </channel>
</rss>

