<?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: Remove duplicate by var ID but keep the highest value of their var age in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Remove-duplicate-by-var-ID-but-keep-the-highest-value-of-their/m-p/837895#M36198</link>
    <description>&lt;P&gt;Double sort or use SQL to control the aggregations more. It really depends on whether you can assume that Name and Age will be constant along with ID.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See this slightly modified example data process (Suza versus Suzi).&lt;/P&gt;
&lt;P&gt;SQL offers you a little more control/options.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example;
input ID $ name $ age kid_age;
cards;
XD546 Alex 18 1
GT786 Yvan 35 10
PE358 Sami 25 5
LK523 Yan 40 18
LK523 Yan 40 15
UY841 Doris 28 14
UY841 Doris 28 8
PQ153 Suzi 38 16
PQ153 Suza 38 8
PQ153 Suzi 38 3
;;;;
run;

proc sort data=example;
by id name age descending kid_age ;
run;


Proc sort data=example
out=clean   
dupout=dups   
nodupkey;
by ID;
run;

proc print data=example;run;

proc print data=clean;run;

proc sql;
create table clean_want as
select id, max(name) as name, max(age) as age, max(kid_age) as kid_age
from example
group by id;
quit;

proc print data=clean_want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 11 Oct 2022 17:37:28 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2022-10-11T17:37:28Z</dc:date>
    <item>
      <title>Remove duplicate by var ID but keep the highest value of their var age</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Remove-duplicate-by-var-ID-but-keep-the-highest-value-of-their/m-p/837879#M36194</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I am trying to remove duplicate value by var ID but I also need to the highest value of the var kid_age for the obs that have duplicate. Is it possible? Could someone help me please?&lt;/P&gt;
&lt;P&gt;I need to have only 1 Obs for each ID but also have the highest value for the var kid_age for the ID that listed more than once in my data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is the SAS programme I used to remove duplicate:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc sort data=Work.base
out=clean   
dupout=dups   
nodupkey;
by ID;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;data example :&lt;/P&gt;
&lt;P&gt;ID name age kid_age &lt;BR /&gt;XD546 Alex 18 1 &lt;BR /&gt;GT786 Yvan 35 10 &lt;BR /&gt;PE358 Sami 25 5 &lt;BR /&gt;LK523 Yan 40 18 &lt;BR /&gt;LK523 Yan 40 15&lt;BR /&gt;UY841 Doris 28 14&lt;BR /&gt;UY841 Doris 28 8&lt;BR /&gt;PQ153 Suzi 38 16&lt;BR /&gt;PQ153 Suzi 38 8&lt;BR /&gt;PQ153 Suzi 38 3&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Oct 2022 16:13:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Remove-duplicate-by-var-ID-but-keep-the-highest-value-of-their/m-p/837879#M36194</guid>
      <dc:creator>Didi_b</dc:creator>
      <dc:date>2022-10-11T16:13:26Z</dc:date>
    </item>
    <item>
      <title>Re: Remove duplicate by var ID but keep the highest value of their var age</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Remove-duplicate-by-var-ID-but-keep-the-highest-value-of-their/m-p/837895#M36198</link>
      <description>&lt;P&gt;Double sort or use SQL to control the aggregations more. It really depends on whether you can assume that Name and Age will be constant along with ID.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See this slightly modified example data process (Suza versus Suzi).&lt;/P&gt;
&lt;P&gt;SQL offers you a little more control/options.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example;
input ID $ name $ age kid_age;
cards;
XD546 Alex 18 1
GT786 Yvan 35 10
PE358 Sami 25 5
LK523 Yan 40 18
LK523 Yan 40 15
UY841 Doris 28 14
UY841 Doris 28 8
PQ153 Suzi 38 16
PQ153 Suza 38 8
PQ153 Suzi 38 3
;;;;
run;

proc sort data=example;
by id name age descending kid_age ;
run;


Proc sort data=example
out=clean   
dupout=dups   
nodupkey;
by ID;
run;

proc print data=example;run;

proc print data=clean;run;

proc sql;
create table clean_want as
select id, max(name) as name, max(age) as age, max(kid_age) as kid_age
from example
group by id;
quit;

proc print data=clean_want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Oct 2022 17:37:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Remove-duplicate-by-var-ID-but-keep-the-highest-value-of-their/m-p/837895#M36198</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-10-11T17:37:28Z</dc:date>
    </item>
    <item>
      <title>Re: Remove duplicate by var ID but keep the highest value of their var age</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Remove-duplicate-by-var-ID-but-keep-the-highest-value-of-their/m-p/837933#M36202</link>
      <description>&lt;LI-CODE lang="sas"&gt;Proc sort data=Work.base;
by ID descending kid_age;
run;

Proc sort data=Work.base
out=clean   
dupout=dups   
nodupkey;
by ID;
run;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if you want just duplicated values:&lt;/P&gt;&lt;PRE&gt;Proc sort data=Work.base
out=dups   
nouniquekey;
by ID;
run;&lt;/PRE&gt;&lt;P&gt;with dupout you keep just deleted values on dups.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Oct 2022 19:49:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Remove-duplicate-by-var-ID-but-keep-the-highest-value-of-their/m-p/837933#M36202</guid>
      <dc:creator>Michelleazevedo</dc:creator>
      <dc:date>2022-10-11T19:49:22Z</dc:date>
    </item>
  </channel>
</rss>

