<?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: Selecting continuous sequences in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Selecting-continuous-sequences/m-p/46613#M12439</link>
    <description>Using PROC SUMMARYwith a CLASS / BY (sorted) list, and then merge back  (a DATA step MERGE with a BY and using IN=I_summary_candidate_var on the summarized file) the candidate summary-level observations back into your detail data (where non-zero condition) to select candidate detail observations.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
    <pubDate>Thu, 18 Jun 2009 19:13:42 GMT</pubDate>
    <dc:creator>sbb</dc:creator>
    <dc:date>2009-06-18T19:13:42Z</dc:date>
    <item>
      <title>Selecting continuous sequences</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Selecting-continuous-sequences/m-p/46612#M12438</link>
      <description>Hello SAS Users,&lt;BR /&gt;
&lt;BR /&gt;
I have a question regarding creating a data set by selecting a sequence of observations in SAS.  I have a data set similar to this:&lt;BR /&gt;
&lt;BR /&gt;
X, Y, COUNT&lt;BR /&gt;
20, 100, 0&lt;BR /&gt;
20, 100, 0&lt;BR /&gt;
20, 100, 1&lt;BR /&gt;
20, 100, 0&lt;BR /&gt;
20, 100, 1&lt;BR /&gt;
20, 100, 1&lt;BR /&gt;
20, 100, 1&lt;BR /&gt;
20, 100, 0&lt;BR /&gt;
&lt;BR /&gt;
21, 101, 1&lt;BR /&gt;
21, 101, 1&lt;BR /&gt;
21, 101, 1&lt;BR /&gt;
21, 101, 0&lt;BR /&gt;
21, 101, 1&lt;BR /&gt;
21, 101, 1&lt;BR /&gt;
21, 101, 1&lt;BR /&gt;
21, 101, 0&lt;BR /&gt;
&lt;BR /&gt;
22, 102, 1&lt;BR /&gt;
22, 102, 1&lt;BR /&gt;
22, 102, 1&lt;BR /&gt;
22, 102, 1&lt;BR /&gt;
22, 102, 1&lt;BR /&gt;
22, 102, 1&lt;BR /&gt;
22, 102, 1&lt;BR /&gt;
22, 102, 0&lt;BR /&gt;
&lt;BR /&gt;
Now, I need to select and output observations that have a continuous sequence of at least three 1's.  For example, where X=20, Y=100, observations 5-7 should be selected;  X=21, Y=101, observations 1-3 and 5-7 should be selected; X=22, Y=102, observation 1-7 should be selected.  Can anybody offer any suggestions?  Thanks in advance.</description>
      <pubDate>Thu, 18 Jun 2009 18:48:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Selecting-continuous-sequences/m-p/46612#M12438</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-18T18:48:08Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting continuous sequences</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Selecting-continuous-sequences/m-p/46613#M12439</link>
      <description>Using PROC SUMMARYwith a CLASS / BY (sorted) list, and then merge back  (a DATA step MERGE with a BY and using IN=I_summary_candidate_var on the summarized file) the candidate summary-level observations back into your detail data (where non-zero condition) to select candidate detail observations.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Thu, 18 Jun 2009 19:13:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Selecting-continuous-sequences/m-p/46613#M12439</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-06-18T19:13:42Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting continuous sequences</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Selecting-continuous-sequences/m-p/46614#M12440</link>
      <description>Hey sas_grad,&lt;BR /&gt;
Here is a different solution to the problem. &lt;BR /&gt;
&lt;BR /&gt;
data dy;&lt;BR /&gt;
infile datalines dlm=',' missover;&lt;BR /&gt;
input x y cnt;&lt;BR /&gt;
datalines;&lt;BR /&gt;
20, 100, 0&lt;BR /&gt;
20, 100, 0&lt;BR /&gt;
20, 100, 1&lt;BR /&gt;
20, 100, 0&lt;BR /&gt;
20, 100, 1&lt;BR /&gt;
20, 100, 1&lt;BR /&gt;
20, 100, 1&lt;BR /&gt;
20, 100, 0&lt;BR /&gt;
21, 101, 1&lt;BR /&gt;
21, 101, 1&lt;BR /&gt;
21, 101, 1&lt;BR /&gt;
21, 101, 0&lt;BR /&gt;
21, 101, 1&lt;BR /&gt;
21, 101, 1&lt;BR /&gt;
21, 101, 1&lt;BR /&gt;
21, 101, 0&lt;BR /&gt;
22, 102, 1&lt;BR /&gt;
22, 102, 1&lt;BR /&gt;
22, 102, 1&lt;BR /&gt;
22, 102, 1&lt;BR /&gt;
22, 102, 1&lt;BR /&gt;
22, 102, 1&lt;BR /&gt;
22, 102, 1&lt;BR /&gt;
22, 102, 0&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
data dy;&lt;BR /&gt;
set dy;&lt;BR /&gt;
by notsorted x y cnt;&lt;BR /&gt;
retain count 0;&lt;BR /&gt;
if first.cnt then count=_n_;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table final as&lt;BR /&gt;
select a.x, a.y, a.cnt,b.count&lt;BR /&gt;
from dy  a&lt;BR /&gt;
	,(	select x, y, cnt, count , count(count)  as xx&lt;BR /&gt;
		from dy  &lt;BR /&gt;
		group by x,y,cnt,count&lt;BR /&gt;
		having count(count) &amp;gt;= 3&lt;BR /&gt;
	)   b&lt;BR /&gt;
where a.count=b.count;&lt;BR /&gt;
quit;&lt;BR /&gt;
proc print;run;&lt;BR /&gt;
&lt;BR /&gt;
Thanks!!!</description>
      <pubDate>Thu, 18 Jun 2009 20:30:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Selecting-continuous-sequences/m-p/46614#M12440</guid>
      <dc:creator>SushilNayak</dc:creator>
      <dc:date>2009-06-18T20:30:35Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting continuous sequences</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Selecting-continuous-sequences/m-p/46615#M12441</link>
      <description>Thanks a bunch, Sushil and Scott.  Sushil, the overall logic of your code was really helpful in solving my problem.</description>
      <pubDate>Mon, 22 Jun 2009 15:47:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Selecting-continuous-sequences/m-p/46615#M12441</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-22T15:47:48Z</dc:date>
    </item>
  </channel>
</rss>

