<?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: Keep only successive observations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Keep-only-successive-observations/m-p/354545#M82947</link>
    <description>&lt;P&gt;Keeping it simple with do until():&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID RN TN OBS;
datalines;
1 1 1 3.2
1 1 2 3.1
1 1 3 4.0
1 1 4 3.9
1 2 1 3.6
1 2 2 3.9
1 2 3 4.2
1 4 1 3.5
1 4 2 4.4
1 4 3 4.1
2 2 1 5.2
2 2 2 4.8
2 2 3 4.9
3 1 1 5.1
3 1 2 5.0
3 1 3 5.0
3 1 4 5.2
3 2 1 5.6
3 2 2 5.3
3 2 3 5.3
3 2 4 4.9
3 2 5 5.1
3 3 1 5.9
3 3 2 5.9
3 3 3 5.8
;

data want;
current = 0;
do until(last.id);
    set have; by id;
    if RN &amp;gt; current + 1 then skip = 1;
    current = RN;
    if not skip then output;
    end;
drop current skip;
run;

proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 28 Apr 2017 17:27:37 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2017-04-28T17:27:37Z</dc:date>
    <item>
      <title>Keep only successive observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-only-successive-observations/m-p/354412#M82917</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;If I have a database of the form:&lt;/P&gt;&lt;P&gt;ID RN TN OBS&lt;BR /&gt;1 1 1 3.2&lt;BR /&gt;1 1 2 3.1&lt;BR /&gt;1 1 3 4.0&lt;BR /&gt;1 1 4 3.9&lt;BR /&gt;1 2 1 3.6&lt;BR /&gt;1 2 2 3.9&lt;BR /&gt;1 2 3 4.2&lt;BR /&gt;1 4 1 3.5&lt;BR /&gt;1 4 2 4.4&lt;BR /&gt;1 4 3 4.1&lt;BR /&gt;2 2 1 5.2&lt;BR /&gt;2 2 2 4.8&lt;BR /&gt;2 2 3 4.9&lt;BR /&gt;3 1 1 5.1&lt;BR /&gt;3 1 2 5.0&lt;BR /&gt;3 1 3 5.0&lt;BR /&gt;3 1 4 5.2&lt;BR /&gt;3 2 1 5.6&lt;BR /&gt;3 2 2 5.3&lt;BR /&gt;3 2 3 5.3&lt;BR /&gt;3 2 4 4.9&lt;BR /&gt;3 2 5 5.1&lt;BR /&gt;3 3 1 5.9&lt;BR /&gt;3 3 2 5.9&lt;BR /&gt;3 3 3 5.8&lt;/P&gt;&lt;P&gt;(ID = identifier, RN = control rank, TN = test number within the control and OBS = Observation)&lt;BR /&gt;If the control row vary from 1 to 4 (in my original database with over 800 miles observations)), how do I keep only individuals with successive control row as 1; 1 and 2; 1, 2 and 3; Or 1, 2, 3 and 4.&lt;/P&gt;&lt;P&gt;If for example an individual has two non-successive control 1 and 3 , because he has missed control&amp;nbsp;2, it will only be shown in the database by control 1.&lt;/P&gt;&lt;P&gt;This means that if an individual misses a control, the next row of conctrol will no longer be considered in the database.&lt;/P&gt;&lt;P&gt;The result of my example is as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;ID RN TN OBS&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1&amp;nbsp;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/FONT&gt; 1 3.2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 1 2 3.1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 1 3 4.0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 1 4 3.9&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt; 1 3.6&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 2 2 3.9&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 2 3 4.2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3 &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/FONT&gt; 1 5.1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3 1 2 5.0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3 1 3 5.0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3 1 4 5.2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3 &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;2&lt;/STRONG&gt;&lt;/FONT&gt; 1 5.6&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3 2 2 5.3&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3 2 3 5.3&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3 2 4 4.9&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3 2 5 5.1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3 &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;3&lt;/STRONG&gt;&lt;/FONT&gt; 1 5.9&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3 3 2 5.9&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3 3 3 5.8&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;thank you for helping me.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2017 10:56:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-only-successive-observations/m-p/354412#M82917</guid>
      <dc:creator>soumri</dc:creator>
      <dc:date>2017-04-28T10:56:26Z</dc:date>
    </item>
    <item>
      <title>Re: Keep only successive observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-only-successive-observations/m-p/354419#M82921</link>
      <description>&lt;P&gt;Below works for you sample data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID RN TN OBS;
datalines;
1 1 1 3.2
1 1 2 3.1
1 1 3 4.0
1 1 4 3.9
1 2 1 3.6
1 2 2 3.9
1 2 3 4.2
1 4 1 3.5
1 4 2 4.4
1 4 3 4.1
2 2 1 5.2
2 2 2 4.8
2 2 3 4.9
3 1 1 5.1
3 1 2 5.0
3 1 3 5.0
3 1 4 5.2
3 2 1 5.6
3 2 2 5.3
3 2 3 5.3
3 2 4 4.9
3 2 5 5.1
3 3 1 5.9
3 3 2 5.9
3 3 3 5.8
;
run;

data want(drop=_:);
  set have;
  by id rn tn;
  _lag_rn=lag(rn);
  retain _delete_flg;

  if first.id then 
    do;
      if rn=1 then _delete_flg=0;
      else _delete_flg=1;
    end;
  else if first.rn and _delete_flg=0 and rn ne _lag_rn+1 then _delete_flg=1;
  if _delete_flg=0 then output;
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Apr 2017 11:16:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-only-successive-observations/m-p/354419#M82921</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-04-28T11:16:39Z</dc:date>
    </item>
    <item>
      <title>Re: Keep only successive observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-only-successive-observations/m-p/354545#M82947</link>
      <description>&lt;P&gt;Keeping it simple with do until():&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID RN TN OBS;
datalines;
1 1 1 3.2
1 1 2 3.1
1 1 3 4.0
1 1 4 3.9
1 2 1 3.6
1 2 2 3.9
1 2 3 4.2
1 4 1 3.5
1 4 2 4.4
1 4 3 4.1
2 2 1 5.2
2 2 2 4.8
2 2 3 4.9
3 1 1 5.1
3 1 2 5.0
3 1 3 5.0
3 1 4 5.2
3 2 1 5.6
3 2 2 5.3
3 2 3 5.3
3 2 4 4.9
3 2 5 5.1
3 3 1 5.9
3 3 2 5.9
3 3 3 5.8
;

data want;
current = 0;
do until(last.id);
    set have; by id;
    if RN &amp;gt; current + 1 then skip = 1;
    current = RN;
    if not skip then output;
    end;
drop current skip;
run;

proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Apr 2017 17:27:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-only-successive-observations/m-p/354545#M82947</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-04-28T17:27:37Z</dc:date>
    </item>
    <item>
      <title>Re: Keep only successive observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-only-successive-observations/m-p/357885#M84068</link>
      <description>&lt;P&gt;Yes it works very well, Thank you very much.&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2017 13:38:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-only-successive-observations/m-p/357885#M84068</guid>
      <dc:creator>soumri</dc:creator>
      <dc:date>2017-05-11T13:38:09Z</dc:date>
    </item>
  </channel>
</rss>

