<?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: proc sort and dupout: how to get the pairs of duplicates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-sort-and-dupout-how-to-get-the-pairs-of-duplicates/m-p/332450#M74830</link>
    <description>&lt;P&gt;How about this? HTH.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=A out=dup_rec nouniquekey; by id age sex win; run;
proc print data=dup_rec noobs; run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 14 Feb 2017 02:32:15 GMT</pubDate>
    <dc:creator>Miracle</dc:creator>
    <dc:date>2017-02-14T02:32:15Z</dc:date>
    <item>
      <title>proc sort and dupout: how to get the pairs of duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sort-and-dupout-how-to-get-the-pairs-of-duplicates/m-p/332446#M74828</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=A out=B dupout=C nodupkey; By var1 var 2 var3 ; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;by using the above code, I can get a dataset unique on By variables (dataset B) and the duplicates on the By variables (dataset C).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sometimes I want to compare the duplicates (unique ones in B and duplicates in C), to see what variables they differ other than the By variables, but how to put them together? I mean how to extract those obs which have the matching By variables &amp;nbsp;in dataset C?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;for example, I have dataset A as:&lt;/P&gt;
&lt;P&gt;ID age sex win lost&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1 20 F 200 120&lt;/P&gt;
&lt;P&gt;2 22 M 150 130&lt;/P&gt;
&lt;P&gt;2 22 M 150 80&lt;/P&gt;
&lt;P&gt;3 25 M 110 90&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;3 25 M 110 210&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;4 27 F &amp;nbsp;105 85&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if I run&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=A out=B dupout=C nodupkey; by ID age sex win; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I will get B as:&lt;/P&gt;
&lt;P&gt;ID age sex win lost&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1 20 F 200 120&lt;/P&gt;
&lt;P&gt;2 22 M 150 130&lt;/P&gt;
&lt;P&gt;3 25 M 110 90&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;4 27 F &amp;nbsp;105 85&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and C:&lt;/P&gt;
&lt;P&gt;ID age sex win lost&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2 22 M 150 80&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;3 25 M 110 210&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Now I want to how other variables in the duplicates differ other than the identical By variables, so I want to have the PAIRS&amp;nbsp;of duplicates like this:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID age sex win lost&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2 22 M 150 130&lt;/P&gt;
&lt;P&gt;2 22 M 150 80&lt;/P&gt;
&lt;P&gt;3 25 M 110 90&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;3 25 M 110 210&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;This means I need to extract the "By variable" identical obs from dataset B. How to do it? Thanks in advance.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2017 01:18:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sort-and-dupout-how-to-get-the-pairs-of-duplicates/m-p/332446#M74828</guid>
      <dc:creator>fengyuwuzu</dc:creator>
      <dc:date>2017-02-14T01:18:48Z</dc:date>
    </item>
    <item>
      <title>Re: proc sort and dupout: how to get the pairs of duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sort-and-dupout-how-to-get-the-pairs-of-duplicates/m-p/332450#M74830</link>
      <description>&lt;P&gt;How about this? HTH.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=A out=dup_rec nouniquekey; by id age sex win; run;
proc print data=dup_rec noobs; run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2017 02:32:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sort-and-dupout-how-to-get-the-pairs-of-duplicates/m-p/332450#M74830</guid>
      <dc:creator>Miracle</dc:creator>
      <dc:date>2017-02-14T02:32:15Z</dc:date>
    </item>
    <item>
      <title>Re: proc sort and dupout: how to get the pairs of duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sort-and-dupout-how-to-get-the-pairs-of-duplicates/m-p/332460#M74834</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data bygroups_having_duplicates;
&amp;nbsp; set b (in=inb) c;
&amp;nbsp; by id age;
&amp;nbsp; if not(first.age=1 and last.age=1);
&amp;nbsp; if inb then source='B';
&amp;nbsp; else source='C';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;No singletons will pass the subsetting if statement.&amp;nbsp; And the first record for each by group will be from dataset B.&amp;nbsp; All subsequent records for the by group are from C.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PROC SQL alternative from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;proc&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;sql&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
create &lt;SPAN class="token statement"&gt;table&lt;/SPAN&gt; d as
&lt;SPAN class="token statement"&gt;select&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;from&lt;/SPAN&gt; a
&lt;SPAN class="token keyword"&gt;group&lt;/SPAN&gt; &lt;SPAN class="token statement"&gt;by&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;id&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; age&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; sex&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; win
having &lt;SPAN class="token function"&gt;count&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;&amp;gt;=&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;2&lt;/SPAN&gt;
&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;quit&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Mar 2018 16:01:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sort-and-dupout-how-to-get-the-pairs-of-duplicates/m-p/332460#M74834</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-03-06T16:01:38Z</dc:date>
    </item>
    <item>
      <title>Re: proc sort and dupout: how to get the pairs of duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sort-and-dupout-how-to-get-the-pairs-of-duplicates/m-p/332497#M74854</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table d as
select * from a
group by id, age, sex, win
having count(*) &amp;gt;= 2
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Feb 2017 07:25:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sort-and-dupout-how-to-get-the-pairs-of-duplicates/m-p/332497#M74854</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-02-14T07:25:26Z</dc:date>
    </item>
    <item>
      <title>Re: proc sort and dupout: how to get the pairs of duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sort-and-dupout-how-to-get-the-pairs-of-duplicates/m-p/332613#M74886</link>
      <description>&lt;P&gt;Thank you very much, all of you! It is so nice to have multiple solutions!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2017 14:01:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sort-and-dupout-how-to-get-the-pairs-of-duplicates/m-p/332613#M74886</guid>
      <dc:creator>fengyuwuzu</dc:creator>
      <dc:date>2017-02-14T14:01:55Z</dc:date>
    </item>
  </channel>
</rss>

