<?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 Why duplicate rows after merging two data sets in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Why-duplicate-rows-after-merging-two-data-sets/m-p/193614#M4095</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'll truly appreciate if somebody helps me out.&lt;/P&gt;&lt;P&gt;I wonder why I get a data including duplicate rows after merging.&lt;/P&gt;&lt;P&gt;My code is following.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=work.A;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /**table A has 500 rows**/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by store product week;&lt;/P&gt;&lt;P&gt;proc sort data=&lt;SPAN style="font-size: 13.3333330154419px;"&gt;work.&lt;/SPAN&gt;B;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /**table B has 800 rows**/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by store product week;&lt;/P&gt;&lt;P&gt;data &lt;SPAN style="font-size: 13.3333330154419px;"&gt;work.A&lt;/SPAN&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; merge &lt;SPAN style="font-size: 13.3333330154419px;"&gt;work.A&lt;/SPAN&gt; (in=in1) &lt;SPAN style="font-size: 13.3333330154419px;"&gt;work.&lt;/SPAN&gt;B (in=in2 keep=&lt;SPAN style="font-size: 13.3333330154419px;"&gt;store product week&lt;/SPAN&gt; advertise);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by &lt;SPAN style="font-size: 13.3333330154419px;"&gt;store product week&lt;/SPAN&gt;;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if in1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;This code is merging table A and B in order to add "advertise" column in the table A.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;I expected the number of table A's rows is 500 since the code has "&lt;SPAN style="font-size: 13.3333330154419px; color: #ff0000;"&gt;if in1;&lt;/SPAN&gt;". However, it was 800. Does anyone know why?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;Jason&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 04 Mar 2015 08:13:36 GMT</pubDate>
    <dc:creator>sarang</dc:creator>
    <dc:date>2015-03-04T08:13:36Z</dc:date>
    <item>
      <title>Why duplicate rows after merging two data sets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Why-duplicate-rows-after-merging-two-data-sets/m-p/193614#M4095</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'll truly appreciate if somebody helps me out.&lt;/P&gt;&lt;P&gt;I wonder why I get a data including duplicate rows after merging.&lt;/P&gt;&lt;P&gt;My code is following.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=work.A;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /**table A has 500 rows**/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by store product week;&lt;/P&gt;&lt;P&gt;proc sort data=&lt;SPAN style="font-size: 13.3333330154419px;"&gt;work.&lt;/SPAN&gt;B;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /**table B has 800 rows**/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by store product week;&lt;/P&gt;&lt;P&gt;data &lt;SPAN style="font-size: 13.3333330154419px;"&gt;work.A&lt;/SPAN&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; merge &lt;SPAN style="font-size: 13.3333330154419px;"&gt;work.A&lt;/SPAN&gt; (in=in1) &lt;SPAN style="font-size: 13.3333330154419px;"&gt;work.&lt;/SPAN&gt;B (in=in2 keep=&lt;SPAN style="font-size: 13.3333330154419px;"&gt;store product week&lt;/SPAN&gt; advertise);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by &lt;SPAN style="font-size: 13.3333330154419px;"&gt;store product week&lt;/SPAN&gt;;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if in1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;This code is merging table A and B in order to add "advertise" column in the table A.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;I expected the number of table A's rows is 500 since the code has "&lt;SPAN style="font-size: 13.3333330154419px; color: #ff0000;"&gt;if in1;&lt;/SPAN&gt;". However, it was 800. Does anyone know why?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;Jason&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Mar 2015 08:13:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Why-duplicate-rows-after-merging-two-data-sets/m-p/193614#M4095</guid>
      <dc:creator>sarang</dc:creator>
      <dc:date>2015-03-04T08:13:36Z</dc:date>
    </item>
    <item>
      <title>Re: Why duplicate rows after merging two data sets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Why-duplicate-rows-after-merging-two-data-sets/m-p/193615#M4096</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You get an observation for each matching obs. As long as every obs in work.B has a match in work.A, they will be included in the output set (because the condition if in1 is always met)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you do not want multiple observations, you need to eliminate the duplicates in Work.B first. Or include a first. or last. condition.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Mar 2015 08:54:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Why-duplicate-rows-after-merging-two-data-sets/m-p/193615#M4096</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2015-03-04T08:54:11Z</dc:date>
    </item>
    <item>
      <title>Re: Why duplicate rows after merging two data sets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Why-duplicate-rows-after-merging-two-data-sets/m-p/193616#M4097</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;Hi Sarang,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You need to remove the duplicates using "nodupkey" option while you sort,&amp;nbsp; this would eliminate your issue.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can try the below code example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data one;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;input store $ product $ week;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;cards;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;1 a 23&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;2 b 45&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;3 a 21&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;1 a 34&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;1 a 23&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;2 b 45&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data two;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;input store $ product $ week advertise $;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;cards;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;1 a 23 y&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;2 b 45 y&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;1 a 34 n&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;2 b 45 y&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;3 a 21 y&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;5 c 45 y&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;7 d 76 y&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;proc sort data=one nodupkey;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;by store product week;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc sort data=two nodupkey;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;by store product week;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data final;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;merge one(in=a) two(in=b keep=store product week advertise);&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;by store product week;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;if a;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Output:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;IMG alt="Capture.JPG" class="jive-image" src="https://communities.sas.com/legacyfs/online/9438_Capture.JPG" /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Daman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Mar 2015 09:37:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Why-duplicate-rows-after-merging-two-data-sets/m-p/193616#M4097</guid>
      <dc:creator>damanaulakh88</dc:creator>
      <dc:date>2015-03-04T09:37:02Z</dc:date>
    </item>
    <item>
      <title>Re: Why duplicate rows after merging two data sets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Why-duplicate-rows-after-merging-two-data-sets/m-p/193617#M4098</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Run this, and take a look at the results. I think this will clarify how the MERGE works.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data a;&lt;/P&gt;&lt;P&gt;input week;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;3&lt;/P&gt;&lt;P&gt;4&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;data b;&lt;/P&gt;&lt;P&gt;input week advertise;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1 9&lt;/P&gt;&lt;P&gt;2 9&lt;/P&gt;&lt;P&gt;2 9&lt;/P&gt;&lt;P&gt;2 9&lt;/P&gt;&lt;P&gt;3 9&lt;/P&gt;&lt;P&gt;4 9&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;data c;&lt;/P&gt;&lt;P&gt;merge a(in=in1) b;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by week;&lt;/P&gt;&lt;P&gt;if in1;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Mar 2015 15:21:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Why-duplicate-rows-after-merging-two-data-sets/m-p/193617#M4098</guid>
      <dc:creator>TomKari</dc:creator>
      <dc:date>2015-03-04T15:21:55Z</dc:date>
    </item>
    <item>
      <title>Re: Why duplicate rows after merging two data sets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Why-duplicate-rows-after-merging-two-data-sets/m-p/193618#M4099</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I really appreciate your answers!&lt;/P&gt;&lt;P&gt;They clarified my misunderstanding of merging.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Mar 2015 16:15:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Why-duplicate-rows-after-merging-two-data-sets/m-p/193618#M4099</guid>
      <dc:creator>sarang</dc:creator>
      <dc:date>2015-03-04T16:15:17Z</dc:date>
    </item>
  </channel>
</rss>

