<?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: One to many merge on SAS in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/One-to-many-merge-on-SAS/m-p/588831#M34666</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/290280"&gt;@cermank&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;...&lt;BR /&gt;
&lt;P&gt;I tried the following patch&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;data c;
merge b(in=inb) a;
by acct_id;
if inb;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But the results are not what i expected. The final dataset has almost double the observations than the b dataset. I'm not sure why that might be happening. What am i doing wrong?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The output C will only have more observations than B when one or more values of ACCT_ID appear more than once in A.&amp;nbsp; If you want to keep only one observation per value of ACCT_ID then you can augment your subsetting IF statement to also test for the flag variable FIRST.ACCT_ID that will be generated because of the BY statement.&lt;/P&gt;</description>
    <pubDate>Sun, 15 Sep 2019 17:51:04 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-09-15T17:51:04Z</dc:date>
    <item>
      <title>One to many merge on SAS</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/One-to-many-merge-on-SAS/m-p/588736#M34660</link>
      <description>&lt;P&gt;I have two datasets.&lt;/P&gt;&lt;P&gt;Dataset A has Account IDs and Balance. Dataset B has Accounts IDs and other variables. Account IDs in dataset B are duplicated.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;data a; 
input acct_id Bal$
21 111
20 222
24 213
26 290
29 300

data b;
input acct_id y$
21 a
21 b
21 c
21 d
21 e

I want to merge these datasets so that i get the following dataset

21 a 111
21 b 111
21 c 111
21 d 111
21 d 111
21 e 111&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I tried the following patch&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;data c
merge b(in=inb) a;
by acct_id;
if inb;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But the results are not what i expected. The final dataset has almost double the observations than the b dataset. I'm not sure why that might be happening. What am i doing wrong?&lt;/P&gt;</description>
      <pubDate>Sat, 14 Sep 2019 17:10:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/One-to-many-merge-on-SAS/m-p/588736#M34660</guid>
      <dc:creator>cermank</dc:creator>
      <dc:date>2019-09-14T17:10:41Z</dc:date>
    </item>
    <item>
      <title>Re: One to many merge on SAS</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/One-to-many-merge-on-SAS/m-p/588738#M34662</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/290280"&gt;@cermank&lt;/a&gt;&amp;nbsp; Your code works fine with a SORT step of both datasets by ACCT_ID before the merge&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data a; 
input acct_id Bal$;
cards;
21 111
20 222
24 213
26 290
29 300
;

data b;
input acct_id y$;
cards;
21 a
21 b
21 c
21 d
21 e
;
proc sort data=a;
by acct_id;
run;
proc sort data=b;
by acct_id;
run;
data c;
merge b(in=inb) a;
by acct_id;
if inb;
run;
proc print noobs;run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.C" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col"&gt;acct_id&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;y&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;Bal&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;21&lt;/TD&gt;
&lt;TD class="l data"&gt;a&lt;/TD&gt;
&lt;TD class="l data"&gt;111&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;21&lt;/TD&gt;
&lt;TD class="l data"&gt;b&lt;/TD&gt;
&lt;TD class="l data"&gt;111&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;21&lt;/TD&gt;
&lt;TD class="l data"&gt;c&lt;/TD&gt;
&lt;TD class="l data"&gt;111&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;21&lt;/TD&gt;
&lt;TD class="l data"&gt;d&lt;/TD&gt;
&lt;TD class="l data"&gt;111&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;21&lt;/TD&gt;
&lt;TD class="l data"&gt;e&lt;/TD&gt;
&lt;TD class="l data"&gt;111&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Sat, 14 Sep 2019 17:19:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/One-to-many-merge-on-SAS/m-p/588738#M34662</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-09-14T17:19:26Z</dc:date>
    </item>
    <item>
      <title>Re: One to many merge on SAS</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/One-to-many-merge-on-SAS/m-p/588739#M34663</link>
      <description>&lt;P&gt;Okay, just a question though. Shouldn't proc sort on acct_id on dataset b delete duplicate ID's? How does it work here?&lt;/P&gt;</description>
      <pubDate>Sat, 14 Sep 2019 17:21:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/One-to-many-merge-on-SAS/m-p/588739#M34663</guid>
      <dc:creator>cermank</dc:creator>
      <dc:date>2019-09-14T17:21:27Z</dc:date>
    </item>
    <item>
      <title>Re: One to many merge on SAS</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/One-to-many-merge-on-SAS/m-p/588740#M34664</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/290280"&gt;@cermank&lt;/a&gt;&amp;nbsp; &amp;nbsp;SORT by name in itself is meant to rearrange records in an order. It could be ascending or descending.&amp;nbsp; Please get your understanding that this is all SORT actually means or does by default. However, yes, you could apply some options to remove duplicates or unique depending upon your requirement. That being said, it is an option within the procedure SORT. Basically, if its sole objective was to remove duplicates, we could rather have a PROC REMOVE_DUPLICATE? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The nomenclature in SAS is in general self explanatory like proc sort, proc means(descriptive stats), proc summary(summary stats), proc freq(frequency) etc. I hope this helps. Btw Welcome to SAS community.&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;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/290280"&gt;@cermank&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Okay, just a question though.&lt;STRONG&gt; Shouldn't proc sort on acct_id on dataset b&lt;FONT color="#FF0000"&gt; delete&lt;/FONT&gt; duplicate ID's?&lt;/STRONG&gt; How does it work here?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Sep 2019 17:27:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/One-to-many-merge-on-SAS/m-p/588740#M34664</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-09-14T17:27:36Z</dc:date>
    </item>
    <item>
      <title>Re: One to many merge on SAS</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/One-to-many-merge-on-SAS/m-p/588741#M34665</link>
      <description>&lt;P&gt;I would even suggest to go for a SQL join to avoid &lt;EM&gt;&lt;STRONG&gt;explicit sort&lt;/STRONG&gt;&lt;/EM&gt;which happens to be a requirement for datastep merge until you have a strong understanding of &lt;EM&gt;&lt;STRONG&gt;match-merge&lt;/STRONG&gt;&lt;/EM&gt; in a datastep based on BY GROUPS.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;So the same objective is achieved by a simple LEFT JOIN:&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 b.*, bal
from b left join a
on b.acct_id=a.acct_id
order by b.acct_id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 14 Sep 2019 17:31:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/One-to-many-merge-on-SAS/m-p/588741#M34665</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-09-14T17:31:15Z</dc:date>
    </item>
    <item>
      <title>Re: One to many merge on SAS</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/One-to-many-merge-on-SAS/m-p/588831#M34666</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/290280"&gt;@cermank&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;...&lt;BR /&gt;
&lt;P&gt;I tried the following patch&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;data c;
merge b(in=inb) a;
by acct_id;
if inb;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But the results are not what i expected. The final dataset has almost double the observations than the b dataset. I'm not sure why that might be happening. What am i doing wrong?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The output C will only have more observations than B when one or more values of ACCT_ID appear more than once in A.&amp;nbsp; If you want to keep only one observation per value of ACCT_ID then you can augment your subsetting IF statement to also test for the flag variable FIRST.ACCT_ID that will be generated because of the BY statement.&lt;/P&gt;</description>
      <pubDate>Sun, 15 Sep 2019 17:51:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/One-to-many-merge-on-SAS/m-p/588831#M34666</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-09-15T17:51:04Z</dc:date>
    </item>
  </channel>
</rss>

