<?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/Merge tables but keeping unique match in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Join-Merge-tables-but-keeping-unique-match/m-p/790878#M253243</link>
    <description>&lt;P&gt;You want this ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x;
input id age sex;
cards;
1 19 1
1 20 0
1 40 0
2 19 1
2 20 0
;

data y;
input id age1 sex1;
cards;
1 19 1
1 20 0
2 19 1
2 20 0
2 22 1
;

data want;
 merge x y;
 by id;
 output;
 call missing(of _all_);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 19 Jan 2022 12:54:39 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2022-01-19T12:54:39Z</dc:date>
    <item>
      <title>Join/Merge tables but keeping unique match</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-Merge-tables-but-keeping-unique-match/m-p/790703#M253176</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to merge two data tables (X and Y) by linking on multiple variables (e.g., age and gender to find matching cases)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Table X&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Participant ID Age Gender&lt;/P&gt;
&lt;P&gt;Table Y&lt;/P&gt;
&lt;P&gt;Encounter# Age Gender&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I did a left join and output shows that some participant IDs are matched up with same encounter #s since the age and gender are equivalent.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm hoping to retain unique encounter #s so if an encounter# is matched with participant ID it will not show up again with other participant ID.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How could I do this?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jan 2022 16:09:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-Merge-tables-but-keeping-unique-match/m-p/790703#M253176</guid>
      <dc:creator>ysk</dc:creator>
      <dc:date>2022-01-18T16:09:21Z</dc:date>
    </item>
    <item>
      <title>Re: Join/Merge tables but keeping unique match</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-Merge-tables-but-keeping-unique-match/m-p/790704#M253177</link>
      <description>&lt;P&gt;You can't with SQL but you can with other approaches. Greedy matching?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Mayo Clinic has a macro:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://bioinformaticstools.mayo.edu/research/gmatch/" target="_blank"&gt;https://bioinformaticstools.mayo.edu/research/gmatch/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And there's PROC PSMATCH for propensity score matching.&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/14733"&gt;@ysk&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi there,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to merge two data tables (X and Y) by linking on multiple variables (e.g., age and gender to find matching cases)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Table X&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Participant ID Age Gender&lt;/P&gt;
&lt;P&gt;Table Y&lt;/P&gt;
&lt;P&gt;Encounter# Age Gender&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I did a left join and output shows that some participant IDs are matched up with same encounter #s since the age and gender are equivalent.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm hoping to retain unique encounter #s so if an encounter# is matched with participant ID it will not show up again with other participant ID.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How could I do this?&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jan 2022 16:14:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-Merge-tables-but-keeping-unique-match/m-p/790704#M253177</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-01-18T16:14:25Z</dc:date>
    </item>
    <item>
      <title>Re: Join/Merge tables but keeping unique match</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-Merge-tables-but-keeping-unique-match/m-p/790829#M253225</link>
      <description>&lt;P&gt;I think it can be done with SQL, something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  select 
    x.*,uniq.encounter from
    x left join (
      select x.*,y.encounter
      from x join y on x.age=y.age and x.sex=y.sex
      group by y.encounter
      having x.participant_id=min(x.participant_id)
   ) uniq on x.participant_id=uniq.participant_id;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Jan 2022 08:50:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-Merge-tables-but-keeping-unique-match/m-p/790829#M253225</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2022-01-19T08:50:42Z</dc:date>
    </item>
    <item>
      <title>Re: Join/Merge tables but keeping unique match</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-Merge-tables-but-keeping-unique-match/m-p/790878#M253243</link>
      <description>&lt;P&gt;You want this ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x;
input id age sex;
cards;
1 19 1
1 20 0
1 40 0
2 19 1
2 20 0
;

data y;
input id age1 sex1;
cards;
1 19 1
1 20 0
2 19 1
2 20 0
2 22 1
;

data want;
 merge x y;
 by id;
 output;
 call missing(of _all_);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Jan 2022 12:54:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-Merge-tables-but-keeping-unique-match/m-p/790878#M253243</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-01-19T12:54:39Z</dc:date>
    </item>
  </channel>
</rss>

