<?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 selecting the series of observation based on some condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/selecting-the-series-of-observation-based-on-some-condition/m-p/273253#M54427</link>
    <description>&lt;P&gt;Hi guys,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;i have a data problem where i have to select out group of observation until certian condition is met ( until i have find flag=1). here is the sample datset:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;input id flag;&lt;BR /&gt;cards;&lt;BR /&gt;001 0&lt;BR /&gt;001 0&lt;BR /&gt;001 0&lt;BR /&gt;001 1&lt;BR /&gt;001 0&lt;BR /&gt;001 0&lt;BR /&gt;002 0&lt;BR /&gt;002 1&lt;BR /&gt;002 0&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;input id flag;&lt;BR /&gt;cards;&lt;BR /&gt;001 0&lt;BR /&gt;001 0&lt;BR /&gt;001 0&lt;BR /&gt;001 1&lt;BR /&gt;002 0&lt;BR /&gt;002 1&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;i was trying to use do loop , but seems like i am doing something wrong:&lt;/P&gt;
&lt;P&gt;here is my try:&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;do until(last.id);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;set have;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;by id;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;do _n_=1 to (f&amp;lt;=1);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;if f&amp;lt;=1; &lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;output;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;end;&lt;BR /&gt;stop;&lt;BR /&gt;run;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but it's not working. Any help is highly appreciated&lt;/P&gt;</description>
    <pubDate>Thu, 26 May 2016 13:20:04 GMT</pubDate>
    <dc:creator>SASFREAK</dc:creator>
    <dc:date>2016-05-26T13:20:04Z</dc:date>
    <item>
      <title>selecting the series of observation based on some condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-the-series-of-observation-based-on-some-condition/m-p/273253#M54427</link>
      <description>&lt;P&gt;Hi guys,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;i have a data problem where i have to select out group of observation until certian condition is met ( until i have find flag=1). here is the sample datset:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;input id flag;&lt;BR /&gt;cards;&lt;BR /&gt;001 0&lt;BR /&gt;001 0&lt;BR /&gt;001 0&lt;BR /&gt;001 1&lt;BR /&gt;001 0&lt;BR /&gt;001 0&lt;BR /&gt;002 0&lt;BR /&gt;002 1&lt;BR /&gt;002 0&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;input id flag;&lt;BR /&gt;cards;&lt;BR /&gt;001 0&lt;BR /&gt;001 0&lt;BR /&gt;001 0&lt;BR /&gt;001 1&lt;BR /&gt;002 0&lt;BR /&gt;002 1&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;i was trying to use do loop , but seems like i am doing something wrong:&lt;/P&gt;
&lt;P&gt;here is my try:&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;do until(last.id);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;set have;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;by id;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;do _n_=1 to (f&amp;lt;=1);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;if f&amp;lt;=1; &lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;output;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;end;&lt;BR /&gt;stop;&lt;BR /&gt;run;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but it's not working. Any help is highly appreciated&lt;/P&gt;</description>
      <pubDate>Thu, 26 May 2016 13:20:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-the-series-of-observation-based-on-some-condition/m-p/273253#M54427</guid>
      <dc:creator>SASFREAK</dc:creator>
      <dc:date>2016-05-26T13:20:04Z</dc:date>
    </item>
    <item>
      <title>Re: selecting the series of observation based on some condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-the-series-of-observation-based-on-some-condition/m-p/273264#M54433</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like:&lt;/P&gt;
&lt;PRE&gt;data want (drop=op);
  set have;
  by id;
  retain op;
  if first.id then op=1;
  if op=1 then output;
  if flag=1 then op=0;
run;
&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 May 2016 14:00:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-the-series-of-observation-based-on-some-condition/m-p/273264#M54433</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-05-26T14:00:46Z</dc:date>
    </item>
    <item>
      <title>Re: selecting the series of observation based on some condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-the-series-of-observation-based-on-some-condition/m-p/273270#M54437</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;LAST.ID will be set to 1 as soon as the end of the first group is reached, so this is why, you only see one group.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Find below a code sample, that will do what you need. It is based on the SUM statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want2;
  set have;
  by id;

  if first.id = 1 then do;
    flagCount = 0;
  end;
  flagCount + (flagCount + flag);

  if flagCount &amp;lt;= 1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bruno&lt;/P&gt;</description>
      <pubDate>Thu, 26 May 2016 14:28:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-the-series-of-observation-based-on-some-condition/m-p/273270#M54437</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2016-05-26T14:28:40Z</dc:date>
    </item>
    <item>
      <title>Re: selecting the series of observation based on some condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-the-series-of-observation-based-on-some-condition/m-p/273279#M54440</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45322"&gt;@SASFREAK﻿&lt;/a&gt;:&amp;nbsp;A&amp;nbsp;DOW loop approach (do until(last. ...)&lt;FONT face="arial,helvetica,sans-serif"&gt;;&lt;/FONT&gt; set ...) was suggested for a very similar question in &lt;A href="https://communities.sas.com/t5/SAS-Statistical-Procedures/Survival-analysis-w-data-structure-of-each-row-being-separate/m-p/272369#M14335" target="_blank"&gt;this recent thread&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 26 May 2016 14:48:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-the-series-of-observation-based-on-some-condition/m-p/273279#M54440</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-05-26T14:48:16Z</dc:date>
    </item>
    <item>
      <title>Re: selecting the series of observation based on some condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-the-series-of-observation-based-on-some-condition/m-p/274649#M54846</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32"&gt;@BrunoMueller﻿&lt;/a&gt; Hi Bruno, Thanks for the solution, but what if i need like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;infile cards missover;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; input id flag switch $8.;&lt;BR /&gt;cards;&lt;BR /&gt;001 0 &lt;BR /&gt;001 0 &lt;BR /&gt;001 0 &lt;BR /&gt;001 1 first&lt;BR /&gt;001 0&lt;BR /&gt;001 0&lt;BR /&gt;001 1 second&lt;BR /&gt;001 0&lt;BR /&gt;001 0&lt;BR /&gt;002 0&lt;BR /&gt;002 1 first&lt;BR /&gt;002 0&lt;BR /&gt;002 0&lt;BR /&gt;002 1 second&lt;BR /&gt;002 1 third&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;/*I need three outputs based on switches i,e.*/&lt;BR /&gt;/**/&lt;BR /&gt;/*data first will looks like:*/&lt;BR /&gt;&lt;BR /&gt;data first;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; input id flag switch $8.;&lt;BR /&gt;cards;&lt;BR /&gt;001 0 &lt;BR /&gt;001 0 &lt;BR /&gt;001 0 &lt;BR /&gt;001 1 first&lt;BR /&gt;002 0&lt;BR /&gt;002 1 first&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;/*this is selecting observation from first to second*/&lt;BR /&gt;data second;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; input id flag switch $8.;&lt;BR /&gt;cards;&lt;BR /&gt;001 1 first&lt;BR /&gt;001 0&lt;BR /&gt;001 0&lt;BR /&gt;001 1 second&lt;BR /&gt;002 1 first&lt;BR /&gt;002 0&lt;BR /&gt;002 0&lt;BR /&gt;002 1 second&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data third;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; input id flag switch $8.;&lt;BR /&gt;cards;&lt;BR /&gt;002 1 second&lt;BR /&gt;002 1 third&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;please help!&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jun 2016 13:06:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-the-series-of-observation-based-on-some-condition/m-p/274649#M54846</guid>
      <dc:creator>SASFREAK</dc:creator>
      <dc:date>2016-06-02T13:06:35Z</dc:date>
    </item>
    <item>
      <title>Re: selecting the series of observation based on some condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-the-series-of-observation-based-on-some-condition/m-p/275020#M54944</link>
      <description>&lt;P&gt;hi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to change the logic for this line&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;flagCount + (flagCount + flag);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;so that you get the right setting.&lt;/P&gt;
&lt;P&gt;For instance&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;flagCount + (flagCount + (switch = "first"));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;will only write the observation til you reach switch = "first"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bruno&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jun 2016 16:29:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-the-series-of-observation-based-on-some-condition/m-p/275020#M54944</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2016-06-03T16:29:56Z</dc:date>
    </item>
  </channel>
</rss>

