<?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: At least two observations for each ID in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/At-least-two-observations-for-each-ID/m-p/270601#M53790</link>
    <description>&lt;P&gt;Or use a data step (assuming that dataset HAVE is sorted by ID):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by id;
if ~(first.id &amp;amp; last.id);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Advantage (over PROC SQL without ORDER BY clause): The order of observations within the BY groups is preserved.&lt;/P&gt;
&lt;P&gt;Disadvantage (shared with the PROC SORT approach): If you change your specifications from "at least two" to, say, "at least &lt;EM&gt;three&lt;/EM&gt; observations per ID," there is more to change in the code than just "&amp;gt;1" into "&amp;gt;2".&lt;/P&gt;</description>
    <pubDate>Sun, 15 May 2016 18:03:52 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2016-05-15T18:03:52Z</dc:date>
    <item>
      <title>At least two observations for each ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/At-least-two-observations-for-each-ID/m-p/270590#M53785</link>
      <description>&lt;P&gt;I have a dataset named "X' with many observations. This is just a sample dataset. I need atleast two observations for each unique ID. For example my dataset looks like below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;date &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; volume&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;03&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; jun1996&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 100&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;04 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;jul1996&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 110&lt;/P&gt;&lt;P&gt;04 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;jul1996&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 120&lt;/P&gt;&lt;P&gt;04 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;aug1996&amp;nbsp;&amp;nbsp;&amp;nbsp; 130&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;05 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;jun1996&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 105&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;06 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; jul1996&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; 110&lt;/P&gt;&lt;P&gt;06 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; jul1996&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 110&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;07 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Jun1996 &amp;nbsp; &amp;nbsp;120&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;08 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Jun1998 &amp;nbsp; &amp;nbsp;130&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My output should look like below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;04 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;jul1996&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 110&lt;/P&gt;&lt;P&gt;04 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;jul1996&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 120&lt;/P&gt;&lt;P&gt;04 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;aug1996&amp;nbsp;&amp;nbsp;&amp;nbsp; 130&lt;/P&gt;&lt;P&gt;06 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; jul1996&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; 110&lt;/P&gt;&lt;P&gt;06 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; jul1996&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 110&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I code in SAS in order to get an output with atleast two observations per ID.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please guide me&lt;/P&gt;</description>
      <pubDate>Sun, 15 May 2016 16:28:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/At-least-two-observations-for-each-ID/m-p/270590#M53785</guid>
      <dc:creator>danwarags</dc:creator>
      <dc:date>2016-05-15T16:28:27Z</dc:date>
    </item>
    <item>
      <title>Re: At least two observations for each ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/At-least-two-observations-for-each-ID/m-p/270596#M53787</link>
      <description>&lt;P&gt;Use SQL:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID date $ volume;
datalines;
03          jun1996     100
04          jul1996      110
04          jul1996      120
04          aug1996    130
05          jun1996     105
06           jul1996      110
06           jul1996      110
07          Jun1996    120
08          Jun1998    130
;

proc sql;
create table want as
select * 
from have
group by ID
having count(*) &amp;gt; 1;
select * from want;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 15 May 2016 17:23:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/At-least-two-observations-for-each-ID/m-p/270596#M53787</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-05-15T17:23:50Z</dc:date>
    </item>
    <item>
      <title>Re: At least two observations for each ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/At-least-two-observations-for-each-ID/m-p/270600#M53789</link>
      <description>&lt;P&gt;You can use the NOUNIKEY option in PROC SORT as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have nounikey out=want;
by id;
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 15 May 2016 17:52:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/At-least-two-observations-for-each-ID/m-p/270600#M53789</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-05-15T17:52:11Z</dc:date>
    </item>
    <item>
      <title>Re: At least two observations for each ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/At-least-two-observations-for-each-ID/m-p/270601#M53790</link>
      <description>&lt;P&gt;Or use a data step (assuming that dataset HAVE is sorted by ID):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by id;
if ~(first.id &amp;amp; last.id);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Advantage (over PROC SQL without ORDER BY clause): The order of observations within the BY groups is preserved.&lt;/P&gt;
&lt;P&gt;Disadvantage (shared with the PROC SORT approach): If you change your specifications from "at least two" to, say, "at least &lt;EM&gt;three&lt;/EM&gt; observations per ID," there is more to change in the code than just "&amp;gt;1" into "&amp;gt;2".&lt;/P&gt;</description>
      <pubDate>Sun, 15 May 2016 18:03:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/At-least-two-observations-for-each-ID/m-p/270601#M53790</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-05-15T18:03:52Z</dc:date>
    </item>
    <item>
      <title>Re: At least two observations for each ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/At-least-two-observations-for-each-ID/m-p/270619#M53799</link>
      <description>&lt;P&gt;Or DOW:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID date $ volume;
datalines;
03          jun1996     100
04          jul1996      110
04          jul1996      120
04          aug1996    130
05          jun1996     105
06           jul1996      110
06           jul1996      110
07          Jun1996    120
08          Jun1998    130
;
run;

data want;
_n_=0;
 do until(last.id);
  set have;
  by id;
  _n_+1;
 end;
 do until(last.id);
  set have;
  by id;
  if _n_ gt 1 then output;
 end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 May 2016 01:17:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/At-least-two-observations-for-each-ID/m-p/270619#M53799</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-05-16T01:17:52Z</dc:date>
    </item>
    <item>
      <title>Re: At least two observations for each ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/At-least-two-observations-for-each-ID/m-p/270760#M53841</link>
      <description>Thank you Reeza. This code helped me to solve my issue.</description>
      <pubDate>Mon, 16 May 2016 19:18:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/At-least-two-observations-for-each-ID/m-p/270760#M53841</guid>
      <dc:creator>danwarags</dc:creator>
      <dc:date>2016-05-16T19:18:49Z</dc:date>
    </item>
  </channel>
</rss>

