<?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 Identify successive observations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Identify-successive-observations/m-p/21562#M3474</link>
    <description>I want to use only collumns with at least five observations and a gap not greater than two years between observations, so I want to delete the first collumn and only keep the second and thirth.&lt;BR /&gt;
&lt;BR /&gt;
datalines&lt;BR /&gt;
1999	1	1	1&lt;BR /&gt;
2000	1	1	1&lt;BR /&gt;
2001	1	1	1&lt;BR /&gt;
2002	.	.	1&lt;BR /&gt;
2003	.	.	1&lt;BR /&gt;
2004	.	1	1&lt;BR /&gt;
2005	1	1	1&lt;BR /&gt;
2006	1	.	1&lt;BR /&gt;
&lt;BR /&gt;
Does annybody know how to do this?</description>
    <pubDate>Tue, 21 Apr 2009 16:20:50 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-04-21T16:20:50Z</dc:date>
    <item>
      <title>Identify successive observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-successive-observations/m-p/21562#M3474</link>
      <description>I want to use only collumns with at least five observations and a gap not greater than two years between observations, so I want to delete the first collumn and only keep the second and thirth.&lt;BR /&gt;
&lt;BR /&gt;
datalines&lt;BR /&gt;
1999	1	1	1&lt;BR /&gt;
2000	1	1	1&lt;BR /&gt;
2001	1	1	1&lt;BR /&gt;
2002	.	.	1&lt;BR /&gt;
2003	.	.	1&lt;BR /&gt;
2004	.	1	1&lt;BR /&gt;
2005	1	1	1&lt;BR /&gt;
2006	1	.	1&lt;BR /&gt;
&lt;BR /&gt;
Does annybody know how to do this?</description>
      <pubDate>Tue, 21 Apr 2009 16:20:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-successive-observations/m-p/21562#M3474</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-04-21T16:20:50Z</dc:date>
    </item>
    <item>
      <title>Re: Identify successive observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-successive-observations/m-p/21563#M3475</link>
      <description>Sorry, but I didn't get it...&lt;BR /&gt;
&lt;BR /&gt;
Being the above dataset the input data, could you please post the result dataset?&lt;BR /&gt;
&lt;BR /&gt;
Greetings from Portugal.&lt;BR /&gt;
&lt;BR /&gt;
Daniel Santos at &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;.</description>
      <pubDate>Tue, 21 Apr 2009 20:04:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-successive-observations/m-p/21563#M3475</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2009-04-21T20:04:10Z</dc:date>
    </item>
    <item>
      <title>Re: Identify successive observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-successive-observations/m-p/21564#M3476</link>
      <description>Could this be helpful to you?&lt;BR /&gt;
&lt;BR /&gt;
data T01_input;&lt;BR /&gt;
infile cards;&lt;BR /&gt;
input year col1 col2 col3;&lt;BR /&gt;
cards;&lt;BR /&gt;
1999 1 1 1&lt;BR /&gt;
2000 1 1 1&lt;BR /&gt;
2001 1 1 1&lt;BR /&gt;
2002 . . 1&lt;BR /&gt;
2003 . . 1&lt;BR /&gt;
2004 . 1 1&lt;BR /&gt;
2005 1 1 1&lt;BR /&gt;
2006 1 . 1&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=T01_input;&lt;BR /&gt;
by year;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
%let variables_to_drop=;&lt;BR /&gt;
&lt;BR /&gt;
data _NULL_;&lt;BR /&gt;
set T01_input end=end_of_file;&lt;BR /&gt;
by year;&lt;BR /&gt;
array gaps       {3} _TEMPORARY_;&lt;BR /&gt;
array gaps_max   {3} _TEMPORARY_;&lt;BR /&gt;
array counts     {3} _TEMPORARY_;&lt;BR /&gt;
array cols       {3} col1-col3;&lt;BR /&gt;
do i=1 to 3;&lt;BR /&gt;
 if cols{i}=. then gaps{i}+1;&lt;BR /&gt;
              else gaps{i}=0;&lt;BR /&gt;
 if gaps{i}&amp;gt;gaps_max{i} then gaps_max{i}=gaps{i};&lt;BR /&gt;
 if cols{i}=1 then counts{i}+1;&lt;BR /&gt;
end;&lt;BR /&gt;
if end_of_file&lt;BR /&gt;
then do i=1 to 3;&lt;BR /&gt;
      variable=vname(cols{i});&lt;BR /&gt;
      max=gaps_max{i};&lt;BR /&gt;
      count=counts{i};&lt;BR /&gt;
      put "Maximum number of consecutive gaps for" variable ": " max "and number of value: " count;&lt;BR /&gt;
      if max gt 2 and count ge 5 then call symput("variables_to_drop",symget('variables_to_drop')||" "||vname(cols{i}));&lt;BR /&gt;
     end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
%put Variables to drop: &amp;amp;variables_to_drop;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table T02_output as&lt;BR /&gt;
select *&lt;BR /&gt;
from T01_input(drop=&amp;amp;variables_to_Drop);&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
This will appear in the log:&lt;BR /&gt;
&lt;BR /&gt;
Maximum number of consecutive gaps forcol1 : 3 and number of value: 5&lt;BR /&gt;
Maximum number of consecutive gaps forcol2 : 2 and number of value: 5&lt;BR /&gt;
Maximum number of consecutive gaps forcol3 : 0 and number of value: 8&lt;BR /&gt;
Variables to drop:  col1&lt;BR /&gt;
&lt;BR /&gt;
The last step would discard col1 from T01_input.&lt;BR /&gt;
&lt;BR /&gt;
Is it what you expect?</description>
      <pubDate>Tue, 21 Apr 2009 20:17:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-successive-observations/m-p/21564#M3476</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-04-21T20:17:08Z</dc:date>
    </item>
    <item>
      <title>Re: Identify successive observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-successive-observations/m-p/21565#M3477</link>
      <description>Dear Yoba,&lt;BR /&gt;
&lt;BR /&gt;
this is exactly what I expected, thanks for your help.&lt;BR /&gt;
&lt;BR /&gt;
greetings from the Netherlands</description>
      <pubDate>Wed, 22 Apr 2009 10:17:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-successive-observations/m-p/21565#M3477</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-04-22T10:17:46Z</dc:date>
    </item>
    <item>
      <title>Re: Identify successive observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-successive-observations/m-p/21566#M3478</link>
      <description>You're welcome,&lt;BR /&gt;
&lt;BR /&gt;
Greetings from ... Belgium (Brussels) &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;</description>
      <pubDate>Wed, 22 Apr 2009 13:36:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-successive-observations/m-p/21566#M3478</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-04-22T13:36:02Z</dc:date>
    </item>
  </channel>
</rss>

