<?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 Drop duplicate and original in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Drop-duplicate-and-original/m-p/322353#M21550</link>
    <description>&lt;P&gt;Folks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've been searching online for a solution to my query, but have yet to find one. In my orginal dataset I had a number of duplicate individuals (however, the information contained within the variables were different). Thus, I originally took out the two columns of information on the individual and aggregated it into one row.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, now I would like to merge it back into my original dataset but firstly I would like to drop all duplicates along with the original. For ease here is a visual example.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;id &amp;nbsp;x1 x2 x3&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; 5 &amp;nbsp; 6 &amp;nbsp; 5&lt;/P&gt;&lt;P&gt;1 &amp;nbsp;10 &amp;nbsp;2 &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; 6 &amp;nbsp; 5 &amp;nbsp; 85&lt;/P&gt;&lt;P&gt;3 63 &amp;nbsp; 2 &amp;nbsp; 11&lt;/P&gt;&lt;P&gt;4 4 &amp;nbsp; 68 &amp;nbsp; &amp;nbsp;95&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;id x1 x2 x3&lt;/P&gt;&lt;P&gt;2 6 &amp;nbsp; &amp;nbsp;5 &amp;nbsp; 85&lt;/P&gt;&lt;P&gt;3 63 &amp;nbsp;2 &amp;nbsp; &amp;nbsp;11&lt;/P&gt;&lt;P&gt;4 4 &amp;nbsp; &amp;nbsp;68 &amp;nbsp; 95&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any advice is welcome.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 04 Jan 2017 09:17:00 GMT</pubDate>
    <dc:creator>Sean_OConnor</dc:creator>
    <dc:date>2017-01-04T09:17:00Z</dc:date>
    <item>
      <title>Drop duplicate and original</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Drop-duplicate-and-original/m-p/322353#M21550</link>
      <description>&lt;P&gt;Folks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've been searching online for a solution to my query, but have yet to find one. In my orginal dataset I had a number of duplicate individuals (however, the information contained within the variables were different). Thus, I originally took out the two columns of information on the individual and aggregated it into one row.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, now I would like to merge it back into my original dataset but firstly I would like to drop all duplicates along with the original. For ease here is a visual example.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;id &amp;nbsp;x1 x2 x3&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; 5 &amp;nbsp; 6 &amp;nbsp; 5&lt;/P&gt;&lt;P&gt;1 &amp;nbsp;10 &amp;nbsp;2 &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; 6 &amp;nbsp; 5 &amp;nbsp; 85&lt;/P&gt;&lt;P&gt;3 63 &amp;nbsp; 2 &amp;nbsp; 11&lt;/P&gt;&lt;P&gt;4 4 &amp;nbsp; 68 &amp;nbsp; &amp;nbsp;95&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;id x1 x2 x3&lt;/P&gt;&lt;P&gt;2 6 &amp;nbsp; &amp;nbsp;5 &amp;nbsp; 85&lt;/P&gt;&lt;P&gt;3 63 &amp;nbsp;2 &amp;nbsp; &amp;nbsp;11&lt;/P&gt;&lt;P&gt;4 4 &amp;nbsp; &amp;nbsp;68 &amp;nbsp; 95&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any advice is welcome.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2017 09:17:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Drop-duplicate-and-original/m-p/322353#M21550</guid>
      <dc:creator>Sean_OConnor</dc:creator>
      <dc:date>2017-01-04T09:17:00Z</dc:date>
    </item>
    <item>
      <title>Re: Drop duplicate and original</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Drop-duplicate-and-original/m-p/322361#M21551</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dupremove;
	input id x1 x2 x3;
	datalines;
2 6 5 85
1 5 6 5
3 4 7 9
9 9 8 8
4 9 23 234
1 10 2 3
23 5 42 3
3 63 2 11
4 4 68 95
;
run;

proc sort data=dupremove;
	by id;
run;

data dupremove;
	set dupremove;
	by id;

	if not first.id=last.id then
		delete;
run;

proc print data=dupremove;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Here you are!&lt;/P&gt;&lt;P&gt;The trick after sorting &amp;nbsp;is the "if not first.id=last.id then delete;" line. This only outputs lines where only a unique id exists. If the first.id and the last.id variable are not 1 it means there is more than one line with the same id. Note you have to have the "by id" in the data step.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2017 10:12:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Drop-duplicate-and-original/m-p/322361#M21551</guid>
      <dc:creator>jefreytag</dc:creator>
      <dc:date>2017-01-04T10:12:14Z</dc:date>
    </item>
    <item>
      <title>Re: Drop duplicate and original</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Drop-duplicate-and-original/m-p/322380#M21556</link>
      <description>&lt;P&gt;I'm afraid that solution won't work when you start with 3 or more observations for the same ID. &amp;nbsp;It's simpler and more reliable to code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if first.id=0 or last.id=0 then delete;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you feel more clever than that, you can try:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if not first.id * last.id;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2017 12:15:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Drop-duplicate-and-original/m-p/322380#M21556</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-01-04T12:15:02Z</dc:date>
    </item>
    <item>
      <title>Re: Drop duplicate and original</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Drop-duplicate-and-original/m-p/322381#M21557</link>
      <description>&lt;P&gt;Absolutely right, missed that logic. Corrected example with enhanced test data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dupremove;
	input id x1 x2 x3;
	datalines;
2 6 5 85
1 5 6 5
3 4 7 9
9 9 8 8
3 8 8 9
3 8 9 9
4 9 23 234
1 10 2 3
23 5 42 3
3 63 2 11
4 4 68 95
;
run;

proc sort data=dupremove;
	by id;
run;

data dupremove;
	set dupremove;
	by id;

if first.id=0 or last.id=0 then
		delete;
run;

proc print data=dupremove;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Jan 2017 12:22:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Drop-duplicate-and-original/m-p/322381#M21557</guid>
      <dc:creator>jefreytag</dc:creator>
      <dc:date>2017-01-04T12:22:57Z</dc:date>
    </item>
  </channel>
</rss>

