<?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: How to select only the first continuous set of satisfying criteria and ignore the rest in a &amp;quot;long&amp;quot; table? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-only-the-first-continuous-set-of-satisfying/m-p/145958#M29071</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Does below code give you the result you're after?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want(drop=_:);&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by id want notsorted;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if first.id then _counter=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if first.want and want=1 then _counter+1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if want=1 and _counter=1 then yn_flg='y';&lt;/P&gt;&lt;P&gt;&amp;nbsp; else yn_flg='n';&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 16 Nov 2013 00:07:59 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2013-11-16T00:07:59Z</dc:date>
    <item>
      <title>How to select only the first continuous set of satisfying criteria and ignore the rest in a "long" table?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-only-the-first-continuous-set-of-satisfying/m-p/145955#M29068</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My data needs to look like this&lt;/P&gt;&lt;P&gt;id&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; want&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; yes/no&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; y&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; y&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; y&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; n&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; n&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; n&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; n&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; y&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; y&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; n&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; n&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; n&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; n&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; n&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; n&lt;/P&gt;&lt;P&gt;basically for each id, I want "y" only for the first continuous want = 1. From the point want = 0, I want to ignore the subsequent rows for that di even if want =1 again for that id.&lt;/P&gt;&lt;P&gt;This is represented by "y" and "n". I need to know how to code so I get the right "y"s and "n"s. I tried do until and do while but my inexperience makes them inexecutable.&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Nov 2013 20:39:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-only-the-first-continuous-set-of-satisfying/m-p/145955#M29068</guid>
      <dc:creator>saurabhc</dc:creator>
      <dc:date>2013-11-15T20:39:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to select only the first continuous set of satisfying criteria and ignore the rest in a "long" table?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-only-the-first-continuous-set-of-satisfying/m-p/145956#M29069</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There must be a more elegant way, but this should do it:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by id want notsorted;&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain yes_no&amp;nbsp; any_1s ' ';&lt;/P&gt;&lt;P&gt;&amp;nbsp; if first.id then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; any_1s='n';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; yes_no='n';&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if first.want then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if want=1 and any_1s='n' then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; yes_no='y';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; any_1s='y';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else yes_no='n';&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; drop any_1s;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Nov 2013 21:09:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-only-the-first-continuous-set-of-satisfying/m-p/145956#M29069</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2013-11-15T21:09:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to select only the first continuous set of satisfying criteria and ignore the rest in a "long" table?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-only-the-first-continuous-set-of-satisfying/m-p/145957#M29070</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There may be some ambiguity in your requirement to "ignore". Do mean to delete the data or not execute some additional code?&lt;/P&gt;&lt;P&gt;You also say " so I get the right "y"s and "n"s." but you don't address which the "right" n's would be. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Nov 2013 22:32:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-only-the-first-continuous-set-of-satisfying/m-p/145957#M29070</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2013-11-15T22:32:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to select only the first continuous set of satisfying criteria and ignore the rest in a "long" table?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-only-the-first-continuous-set-of-satisfying/m-p/145958#M29071</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Does below code give you the result you're after?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want(drop=_:);&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by id want notsorted;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if first.id then _counter=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if first.want and want=1 then _counter+1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if want=1 and _counter=1 then yn_flg='y';&lt;/P&gt;&lt;P&gt;&amp;nbsp; else yn_flg='n';&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 16 Nov 2013 00:07:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-only-the-first-continuous-set-of-satisfying/m-p/145958#M29071</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2013-11-16T00:07:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to select only the first continuous set of satisfying criteria and ignore the rest in a "long" table?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-only-the-first-continuous-set-of-satisfying/m-p/145959#M29072</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Astounding,&lt;/P&gt;&lt;P&gt;The code you gave totally works after adjusting it to my actual data. Basically there were also multiple dates with the ids but they did not matter as long as my indicator "want" had preselected my desirable observations.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 16 Nov 2013 00:13:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-only-the-first-continuous-set-of-satisfying/m-p/145959#M29072</guid>
      <dc:creator>saurabhc</dc:creator>
      <dc:date>2013-11-16T00:13:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to select only the first continuous set of satisfying criteria and ignore the rest in a "long" table?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-only-the-first-continuous-set-of-satisfying/m-p/145960#M29073</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi ballardw,&lt;/P&gt;&lt;P&gt;What I meant is this, keep flagging or counting or whatever, until the want changes to a zero. Once a want changes to zero, it does not matter even if it changes to a want = 1 again for that particular id. Basically, I just want the first "set" of continuous want = 1 for any given id and ignore the want = 0 and the subsequent want = 1 (in sets or single).&lt;/P&gt;&lt;P&gt;Ignore could mean drop the observation or just change the flag or stop counting or whatever (like above). The idea is the same.&lt;/P&gt;&lt;P&gt;Sorry about the ambiguity.&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;PS: All ids always start with want = 1 in my dataset.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 16 Nov 2013 00:17:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-only-the-first-continuous-set-of-satisfying/m-p/145960#M29073</guid>
      <dc:creator>saurabhc</dc:creator>
      <dc:date>2013-11-16T00:17:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to select only the first continuous set of satisfying criteria and ignore the rest in a "long" table?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-only-the-first-continuous-set-of-satisfying/m-p/145961#M29074</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Patrick,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you. Your code works too! It is nice to know how different lines produce the same result because they make different use of similar logic.&lt;/P&gt;&lt;P&gt;Thanks again.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 16 Nov 2013 00:25:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-only-the-first-continuous-set-of-satisfying/m-p/145961#M29074</guid>
      <dc:creator>saurabhc</dc:creator>
      <dc:date>2013-11-16T00:25:00Z</dc:date>
    </item>
  </channel>
</rss>

