<?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: Select 3 rows for each unique ID in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Select-3-rows-for-each-unique-ID/m-p/337303#M76585</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id  address $;
datalines;
1    A
1    B
1    C
2    HH
2    KK
2    NN
2    MM
;
run;

proc surveyselect data=have out=want sampsize=3;
strata id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 02 Mar 2017 11:01:49 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2017-03-02T11:01:49Z</dc:date>
    <item>
      <title>Select 3 rows for each unique ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-3-rows-for-each-unique-ID/m-p/337252#M76571</link>
      <description>&lt;P&gt;Each unique ID have many different rows of &amp;nbsp;addresses, I want a program to select for each unqiue ID any 3 rows of addressses.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example of dataset:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID&amp;nbsp; Address&lt;/P&gt;
&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp; A&lt;/P&gt;
&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp; B&lt;/P&gt;
&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp; C&lt;/P&gt;
&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp; HH&lt;/P&gt;
&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp; KK&lt;/P&gt;
&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp; NN&lt;/P&gt;
&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp; MM&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2017 07:34:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-3-rows-for-each-unique-ID/m-p/337252#M76571</guid>
      <dc:creator>apple</dc:creator>
      <dc:date>2017-03-02T07:34:28Z</dc:date>
    </item>
    <item>
      <title>Re: Select 3 rows for each unique ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-3-rows-for-each-unique-ID/m-p/337263#M76577</link>
      <description>&lt;P&gt;If the data is sorted as per your example, use data step with BY ID, and use a counter that is re-initiated for each first.ID.&lt;/P&gt;
&lt;P&gt;Use explicit output when the counter is &amp;lt;= 3.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2017 08:42:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-3-rows-for-each-unique-ID/m-p/337263#M76577</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2017-03-02T08:42:23Z</dc:date>
    </item>
    <item>
      <title>Re: Select 3 rows for each unique ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-3-rows-for-each-unique-ID/m-p/337273#M76580</link>
      <description>&lt;P&gt;Just a slight alteration of&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13674"&gt;@LinusH&lt;/a&gt;&amp;nbsp;answer uses lag to decide if to output or not (saves a variable and line of code):&lt;/P&gt;
&lt;PRE&gt;data have;
  input id  address $;
datalines;
1    A
1    B
1    C
2    HH
2    KK
2    NN
2    MM
;
run;
data want;
  set have;
  by id;
  if first.id or lag(first.id) or lag2(first.id) then output;
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Mar 2017 09:14:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-3-rows-for-each-unique-ID/m-p/337273#M76580</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-03-02T09:14:57Z</dc:date>
    </item>
    <item>
      <title>Re: Select 3 rows for each unique ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-3-rows-for-each-unique-ID/m-p/337303#M76585</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id  address $;
datalines;
1    A
1    B
1    C
2    HH
2    KK
2    NN
2    MM
;
run;

proc surveyselect data=have out=want sampsize=3;
strata id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Mar 2017 11:01:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-3-rows-for-each-unique-ID/m-p/337303#M76585</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-03-02T11:01:49Z</dc:date>
    </item>
  </channel>
</rss>

