<?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: SAS select or keep only one of duplicate observations in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/SAS-select-or-keep-only-one-of-duplicate-observations/m-p/834481#M35887</link>
    <description>&lt;P&gt;Sort, then use a data step with BY:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have,
by id week money;
run;

data want;
set have;
by id week;
if last.week;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested, posted from my tablet.&lt;/P&gt;</description>
    <pubDate>Wed, 21 Sep 2022 14:10:17 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2022-09-21T14:10:17Z</dc:date>
    <item>
      <title>SAS select or keep only one of duplicate observations</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SAS-select-or-keep-only-one-of-duplicate-observations/m-p/834475#M35886</link>
      <description>&lt;P&gt;Hello SAS community, I have a quick question. Consider the following simple data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data have;
input id city $ week money @@;
datalines;
1 A 1 100
1 A 2 105
1 A 5 108
1 B 5 206
1 B 7 99
1 C 8 101
1 C 10 110
2 B 5 202
2 C 5 100
2 D 8 95
2 E 8 98
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I would like the observations for each ID have unique week. If for each subject there are duplicate 'week', the 'week' with larger money variable would be kept. So:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data want;
input id city $ week money @@;
datalines;
1 A 1 100
1 A 2 105
1 B 5 206
1 B 7 99
1 C 8 101
1 C 10 110
2 B 5 202
2 E 8 98
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Can this be done via some data steps? Or SQL is a must? Might someone be willing to assist? Thank you in advance!&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;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Sep 2022 13:35:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SAS-select-or-keep-only-one-of-duplicate-observations/m-p/834475#M35886</guid>
      <dc:creator>hellorc</dc:creator>
      <dc:date>2022-09-21T13:35:43Z</dc:date>
    </item>
    <item>
      <title>Re: SAS select or keep only one of duplicate observations</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SAS-select-or-keep-only-one-of-duplicate-observations/m-p/834481#M35887</link>
      <description>&lt;P&gt;Sort, then use a data step with BY:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have,
by id week money;
run;

data want;
set have;
by id week;
if last.week;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested, posted from my tablet.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Sep 2022 14:10:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SAS-select-or-keep-only-one-of-duplicate-observations/m-p/834481#M35887</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-09-21T14:10:17Z</dc:date>
    </item>
  </channel>
</rss>

