<?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: Picking the first record when there's a 1-to-mnay relationship in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Picking-the-first-record-when-there-s-a-1-to-mnay-relationship/m-p/767681#M243422</link>
    <description>&lt;PRE&gt;data have;
  input ID Name $30.;
cards;
3 John Smith
3 Andrew Smith
1 John Doe
2 Bozo the Clown
2 Felix the Cat
;

proc sql;
create table want as
select * from have group by id having name=max(name);
quit;&lt;/PRE&gt;</description>
    <pubDate>Tue, 14 Sep 2021 12:37:40 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2021-09-14T12:37:40Z</dc:date>
    <item>
      <title>Picking the first record when there's a 1-to-mnay relationship</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Picking-the-first-record-when-there-s-a-1-to-mnay-relationship/m-p/767514#M243336</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;I'm a super novice SAS SQL coder. I have a data set (call it test) that has that looks something like this:&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp;Name&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;John Smith&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Andrew Smith&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;John Doe&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Bozo the Clown&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Felix the Cat&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want to do is is keep just one record for ID #2 and ID #3. I don't care which record, Name could be sorted alphabetically and I could keep the first or last so I get back this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp;Name&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;John Doe&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Felix the Cat&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;John Smith&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can do this in Access, but I have millions of records and I think SAS is a much better tool to do this.&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Sep 2021 18:29:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Picking-the-first-record-when-there-s-a-1-to-mnay-relationship/m-p/767514#M243336</guid>
      <dc:creator>dxtran</dc:creator>
      <dc:date>2021-09-13T18:29:40Z</dc:date>
    </item>
    <item>
      <title>Re: Picking the first record when there's a 1-to-mnay relationship</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Picking-the-first-record-when-there-s-a-1-to-mnay-relationship/m-p/767516#M243338</link>
      <description>&lt;P&gt;Just sort and use BY group processing in a data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input ID Name $30.;
cards;
3 John Smith
3 Andrew Smith
1 John Doe
2 Bozo the Clown
2 Felix the Cat
;

proc sort data=have out=want;
  by id name;
run;

data want;
  set want;
  by id;
  if last.id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Sep 2021 18:34:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Picking-the-first-record-when-there-s-a-1-to-mnay-relationship/m-p/767516#M243338</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-09-13T18:34:24Z</dc:date>
    </item>
    <item>
      <title>Re: Picking the first record when there's a 1-to-mnay relationship</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Picking-the-first-record-when-there-s-a-1-to-mnay-relationship/m-p/767518#M243339</link>
      <description>&lt;P&gt;Thank you for the super quick response Tom!&lt;/P&gt;</description>
      <pubDate>Mon, 13 Sep 2021 18:44:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Picking-the-first-record-when-there-s-a-1-to-mnay-relationship/m-p/767518#M243339</guid>
      <dc:creator>dxtran</dc:creator>
      <dc:date>2021-09-13T18:44:43Z</dc:date>
    </item>
    <item>
      <title>Re: Picking the first record when there's a 1-to-mnay relationship</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Picking-the-first-record-when-there-s-a-1-to-mnay-relationship/m-p/767681#M243422</link>
      <description>&lt;PRE&gt;data have;
  input ID Name $30.;
cards;
3 John Smith
3 Andrew Smith
1 John Doe
2 Bozo the Clown
2 Felix the Cat
;

proc sql;
create table want as
select * from have group by id having name=max(name);
quit;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Sep 2021 12:37:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Picking-the-first-record-when-there-s-a-1-to-mnay-relationship/m-p/767681#M243422</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-09-14T12:37:40Z</dc:date>
    </item>
    <item>
      <title>Re: Picking the first record when there's a 1-to-mnay relationship</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Picking-the-first-record-when-there-s-a-1-to-mnay-relationship/m-p/767734#M243435</link>
      <description>&lt;P&gt;If there multiple observations with the same value of name for an ID you could end up with multiple observations for the same value of ID.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Sep 2021 14:29:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Picking-the-first-record-when-there-s-a-1-to-mnay-relationship/m-p/767734#M243435</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-09-14T14:29:36Z</dc:date>
    </item>
    <item>
      <title>Re: Picking the first record when there's a 1-to-mnay relationship</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Picking-the-first-record-when-there-s-a-1-to-mnay-relationship/m-p/767871#M243495</link>
      <description>Sure. It is depend on what OP want .</description>
      <pubDate>Wed, 15 Sep 2021 11:52:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Picking-the-first-record-when-there-s-a-1-to-mnay-relationship/m-p/767871#M243495</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-09-15T11:52:54Z</dc:date>
    </item>
  </channel>
</rss>

