<?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: Select rows till a particular vale in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Select-rows-till-a-particular-vale/m-p/430549#M106429</link>
    <description>Thank you draycut. What if there are values in hs column with just 0s and no 1s like below&lt;BR /&gt;&lt;BR /&gt;data have;&lt;BR /&gt;input id term $ hs ;&lt;BR /&gt;datalines;&lt;BR /&gt;123 200802 1&lt;BR /&gt;123 200901 1&lt;BR /&gt;123 201002 0&lt;BR /&gt;123 201003 0&lt;BR /&gt;123 201011 0&lt;BR /&gt;245 200401 1&lt;BR /&gt;245 200402 1&lt;BR /&gt;245 200403 1&lt;BR /&gt;245 201001 0&lt;BR /&gt;245 201002 0&lt;BR /&gt;321 200902 0&lt;BR /&gt;321 201001 0&lt;BR /&gt;321 201102 0&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;I need to keep the id with just the 0s as is. It should look like this&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;input id term $ hs ;&lt;BR /&gt;datalines;&lt;BR /&gt;123 200802 1&lt;BR /&gt;123 200901 1&lt;BR /&gt;123 201002 0&lt;BR /&gt;245 200401 1&lt;BR /&gt;245 200402 1&lt;BR /&gt;245 200403 1&lt;BR /&gt;245 201001 0&lt;BR /&gt;321 200902 0&lt;BR /&gt;321 201001 0&lt;BR /&gt;321 201102 0&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;Thanks. Your other scripts work for the test run but when I run it against my full data set I get "variable hs is uninitialized", thoughts on that?&lt;BR /&gt;Thanks</description>
    <pubDate>Wed, 24 Jan 2018 17:16:22 GMT</pubDate>
    <dc:creator>anandas</dc:creator>
    <dc:date>2018-01-24T17:16:22Z</dc:date>
    <item>
      <title>Select rows till a particular vale</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-rows-till-a-particular-vale/m-p/430493#M106408</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a table where I need all rows of data till it stops at a particular value.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The original table looks like this.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="Before.JPG" style="width: 274px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18079i2E91FEBFCCDC60F5/image-size/large?v=v2&amp;amp;px=999" role="button" title="Before.JPG" alt="Before.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want the table to look like this. I want the observations to stop at the first '0' value in the 'hs' column (the third column).&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="After.JPG" style="width: 269px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18081i955ABF6A571A7543/image-size/large?v=v2&amp;amp;px=999" role="button" title="After.JPG" alt="After.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2018 15:29:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-rows-till-a-particular-vale/m-p/430493#M106408</guid>
      <dc:creator>anandas</dc:creator>
      <dc:date>2018-01-24T15:29:15Z</dc:date>
    </item>
    <item>
      <title>Re: Select rows till a particular vale</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-rows-till-a-particular-vale/m-p/430496#M106410</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id$ term hs;
datalines;
123 200802 1
123 200901 1
123 201002 0
123 201003 0
123 201101 0
;

data want;
   set have;
   if hs=0 then do;
      output;
      stop;
   end;
   output;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Jan 2018 15:40:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-rows-till-a-particular-vale/m-p/430496#M106410</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-01-24T15:40:20Z</dc:date>
    </item>
    <item>
      <title>Re: Select rows till a particular vale</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-rows-till-a-particular-vale/m-p/430500#M106412</link>
      <description>Thank you. I forgot to mention I have multiple ids. In other words, I want this condition by each unique id. I just gave an example for one unique id. Can you do for this table? Thanks.&lt;BR /&gt;&lt;BR /&gt;data test;&lt;BR /&gt;input id term $ hs $;&lt;BR /&gt;datalines;&lt;BR /&gt;123 200802 1&lt;BR /&gt;123 200901 1&lt;BR /&gt;123 201002 0&lt;BR /&gt;123 201003 0&lt;BR /&gt;123 201101 0&lt;BR /&gt;245 200401 1&lt;BR /&gt;245 200402 1&lt;BR /&gt;245 200403 1&lt;BR /&gt;245 201001 0&lt;BR /&gt;245 201002 0&lt;BR /&gt;;&lt;BR /&gt;run;</description>
      <pubDate>Wed, 24 Jan 2018 15:44:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-rows-till-a-particular-vale/m-p/430500#M106412</guid>
      <dc:creator>anandas</dc:creator>
      <dc:date>2018-01-24T15:44:39Z</dc:date>
    </item>
    <item>
      <title>Re: Select rows till a particular vale</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-rows-till-a-particular-vale/m-p/430505#M106413</link>
      <description>&lt;P&gt;Just to clarify. So in this case, your want data set looks like this right?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
input id term $ hs $;
datalines;
123 200802 1
123 200901 1
123 201002 0
245 200401 1
245 200402 1
245 200403 1
245 201001 0
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also, are the values of hs always only 0s and 1s?&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2018 15:53:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-rows-till-a-particular-vale/m-p/430505#M106413</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-01-24T15:53:12Z</dc:date>
    </item>
    <item>
      <title>Re: Select rows till a particular vale</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-rows-till-a-particular-vale/m-p/430508#M106414</link>
      <description>Thank you. Yes, it should look like how you have written. There are only two values in hs - 0 and 1.&lt;BR /&gt;Thank you.</description>
      <pubDate>Wed, 24 Jan 2018 15:54:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-rows-till-a-particular-vale/m-p/430508#M106414</guid>
      <dc:creator>anandas</dc:creator>
      <dc:date>2018-01-24T15:54:54Z</dc:date>
    </item>
    <item>
      <title>Re: Select rows till a particular vale</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-rows-till-a-particular-vale/m-p/430520#M106416</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input id term $ hs ;
datalines;
123 200802 1
123 200901 1
123 201002 0
123 201003 0
123 201101 0
245 200401 1
245 200402 1
245 200403 1
245 201001 0
245 201002 0
;
run;




data want;
_flag=0;
do until(last.id);
set test;
by id;
if not _flag and hs=0 then do;_flag=1;output;continue;end;
else if not _flag then output;
end;
drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Jan 2018 16:20:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-rows-till-a-particular-vale/m-p/430520#M106416</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-01-24T16:20:12Z</dc:date>
    </item>
    <item>
      <title>Re: Select rows till a particular vale</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-rows-till-a-particular-vale/m-p/430533#M106420</link>
      <description>&lt;P&gt;Ok. Do simply like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set test;
   if hs='1' or (hs='0' and lag(hs)='1');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Jan 2018 16:44:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-rows-till-a-particular-vale/m-p/430533#M106420</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-01-24T16:44:18Z</dc:date>
    </item>
    <item>
      <title>Re: Select rows till a particular vale</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-rows-till-a-particular-vale/m-p/430545#M106425</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;Not quite mate!, I added a couple of rows(&lt;STRONG&gt;what if)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;245 200401 1&lt;BR /&gt;245 200402 1&lt;BR /&gt;245 200403 1&lt;BR /&gt;245 201001 0&lt;BR /&gt;245 201002 0&lt;BR /&gt;&lt;STRONG&gt;245 201002 1(What if)&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;245 201002 0(what if)&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2018 17:08:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-rows-till-a-particular-vale/m-p/430545#M106425</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-01-24T17:08:18Z</dc:date>
    </item>
    <item>
      <title>Re: Select rows till a particular vale</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-rows-till-a-particular-vale/m-p/430549#M106429</link>
      <description>Thank you draycut. What if there are values in hs column with just 0s and no 1s like below&lt;BR /&gt;&lt;BR /&gt;data have;&lt;BR /&gt;input id term $ hs ;&lt;BR /&gt;datalines;&lt;BR /&gt;123 200802 1&lt;BR /&gt;123 200901 1&lt;BR /&gt;123 201002 0&lt;BR /&gt;123 201003 0&lt;BR /&gt;123 201011 0&lt;BR /&gt;245 200401 1&lt;BR /&gt;245 200402 1&lt;BR /&gt;245 200403 1&lt;BR /&gt;245 201001 0&lt;BR /&gt;245 201002 0&lt;BR /&gt;321 200902 0&lt;BR /&gt;321 201001 0&lt;BR /&gt;321 201102 0&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;I need to keep the id with just the 0s as is. It should look like this&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;input id term $ hs ;&lt;BR /&gt;datalines;&lt;BR /&gt;123 200802 1&lt;BR /&gt;123 200901 1&lt;BR /&gt;123 201002 0&lt;BR /&gt;245 200401 1&lt;BR /&gt;245 200402 1&lt;BR /&gt;245 200403 1&lt;BR /&gt;245 201001 0&lt;BR /&gt;321 200902 0&lt;BR /&gt;321 201001 0&lt;BR /&gt;321 201102 0&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;Thanks. Your other scripts work for the test run but when I run it against my full data set I get "variable hs is uninitialized", thoughts on that?&lt;BR /&gt;Thanks</description>
      <pubDate>Wed, 24 Jan 2018 17:16:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-rows-till-a-particular-vale/m-p/430549#M106429</guid>
      <dc:creator>anandas</dc:creator>
      <dc:date>2018-01-24T17:16:22Z</dc:date>
    </item>
    <item>
      <title>Re: Select rows till a particular vale</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-rows-till-a-particular-vale/m-p/430553#M106431</link>
      <description>&lt;P&gt;tweaked to meet you requirement&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id term $ hs ;
datalines;
123 200802 1
123 200901 1
123 201002 0
123 201003 0
123 201011 0
245 200401 1
245 200402 1
245 200403 1
245 201001 0
245 201002 0
321 200902 0
321 201001 0
321 201102 0
;
run;


data want;
_flag=0;
do until(last.id);
set have;
by id;
if not _flag and lag(hs)=1 and hs=0 then do;_flag=1;output;continue;end;
else if not _flag then output;
end;
drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Jan 2018 17:26:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-rows-till-a-particular-vale/m-p/430553#M106431</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-01-24T17:26:31Z</dc:date>
    </item>
    <item>
      <title>Re: Select rows till a particular vale</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-rows-till-a-particular-vale/m-p/430556#M106433</link>
      <description>&lt;P&gt;Jumping into the fray before this gets too complicated:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by id;&lt;/P&gt;
&lt;P&gt;if first.id then output_yn='Y';&lt;/P&gt;
&lt;P&gt;retain output_yn;&lt;/P&gt;
&lt;P&gt;if output_yn='Y' then output;&lt;/P&gt;
&lt;P&gt;if hs='0' then output_yn='N';&lt;/P&gt;
&lt;P&gt;drop output_yn;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I kept HS as a character variable, since it seems that's what is in your current data.&amp;nbsp; But converting it to numeric would be OK.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2018 17:34:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-rows-till-a-particular-vale/m-p/430556#M106433</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-01-24T17:34:40Z</dc:date>
    </item>
    <item>
      <title>Re: Select rows till a particular vale</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-rows-till-a-particular-vale/m-p/430560#M106435</link>
      <description>&lt;P&gt;Thank you to&amp;nbsp;novinosrin and&amp;nbsp;draycut. Your script worked.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2018 17:38:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-rows-till-a-particular-vale/m-p/430560#M106435</guid>
      <dc:creator>anandas</dc:creator>
      <dc:date>2018-01-24T17:38:25Z</dc:date>
    </item>
    <item>
      <title>Re: Select rows till a particular vale</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-rows-till-a-particular-vale/m-p/430561#M106436</link>
      <description>&lt;P&gt;Thank you to astounding. Your script worked too. i will keep yours too and study it as well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Much appreciated!&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2018 17:38:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-rows-till-a-particular-vale/m-p/430561#M106436</guid>
      <dc:creator>anandas</dc:creator>
      <dc:date>2018-01-24T17:38:58Z</dc:date>
    </item>
  </channel>
</rss>

