<?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: Dropping observations after a certain value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Dropping-observations-after-a-certain-value/m-p/244754#M268513</link>
    <description>&lt;P&gt;Will you ever have a case where the 'b' values aren't sequential such as this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;A, B, 

1, a, 
1, b,
1, c,
1, b
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is the case where the group starts with 'b' treated any differently?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;A, B, 
1, b, 
1, b,
1, c,
1, c

would still return 2 values?
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If no to both of those this may work for you&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;
   by notsorted a notsorted b;
   retain flag 0;
   if first.a then flag=1;
   if B='b' and last.b then do;
      output;
      flag=0;
   end;
   if flag then output;
   drop flag;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 20 Jan 2016 16:55:05 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2016-01-20T16:55:05Z</dc:date>
    <item>
      <title>Dropping observations after a certain value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dropping-observations-after-a-certain-value/m-p/244752#M268512</link>
      <description>&lt;P&gt;I have a data set with lets say 2 &amp;nbsp;variables A &amp;amp; B (in actual fact there are around 70 variables but these are the only two I am interested in)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;A, B,&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;1, a,&amp;nbsp;&lt;/P&gt;&lt;P&gt;1, b,&lt;/P&gt;&lt;P&gt;1, c,&lt;/P&gt;&lt;P&gt;1, c&lt;/P&gt;&lt;P&gt;2, d&lt;/P&gt;&lt;P&gt;2, d&lt;/P&gt;&lt;P&gt;2, d&lt;/P&gt;&lt;P&gt;2, b&lt;/P&gt;&lt;P&gt;2, b&lt;/P&gt;&lt;P&gt;3, a&lt;/P&gt;&lt;P&gt;3, c&lt;/P&gt;&lt;P&gt;3, b&lt;/P&gt;&lt;P&gt;3, b&lt;/P&gt;&lt;P&gt;3, d&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I only want to output observations for each A value up until the B value equals B. So from&amp;nbsp;first.A until B no longer = 'b', and this is repeated for each A value. I'm trying to use a do while loop but it doesn't seem to be working.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So in this example it would keep the first two observations where A = 1&lt;/P&gt;&lt;P&gt;the first 5 observations where A = 2&lt;/P&gt;&lt;P&gt;and the first 4 observations where A = 3.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The values of B before B = 'b' are not always the same and can be made up of any combination of values except 'b'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any Ideas?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2016 16:39:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dropping-observations-after-a-certain-value/m-p/244752#M268512</guid>
      <dc:creator>OrangePiper</dc:creator>
      <dc:date>2016-01-20T16:39:30Z</dc:date>
    </item>
    <item>
      <title>Re: Dropping observations after a certain value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dropping-observations-after-a-certain-value/m-p/244754#M268513</link>
      <description>&lt;P&gt;Will you ever have a case where the 'b' values aren't sequential such as this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;A, B, 

1, a, 
1, b,
1, c,
1, b
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is the case where the group starts with 'b' treated any differently?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;A, B, 
1, b, 
1, b,
1, c,
1, c

would still return 2 values?
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If no to both of those this may work for you&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;
   by notsorted a notsorted b;
   retain flag 0;
   if first.a then flag=1;
   if B='b' and last.b then do;
      output;
      flag=0;
   end;
   if flag then output;
   drop flag;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2016 16:55:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dropping-observations-after-a-certain-value/m-p/244754#M268513</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-01-20T16:55:05Z</dc:date>
    </item>
    <item>
      <title>Re: Dropping observations after a certain value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dropping-observations-after-a-certain-value/m-p/244767#M268514</link>
      <description>&lt;P&gt;Do you want the first 'b'?&amp;nbsp; If not this will do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;infile cards dsd;&lt;BR /&gt;input A&amp;nbsp; B$;&lt;BR /&gt;cards;&lt;BR /&gt;1, a&lt;BR /&gt;1, b&lt;BR /&gt;1, c&lt;BR /&gt;1, c&lt;BR /&gt;2, d&lt;BR /&gt;2, d&lt;BR /&gt;2, d&lt;BR /&gt;2, b&lt;BR /&gt;2, b&lt;BR /&gt;3, a&lt;BR /&gt;3, c&lt;BR /&gt;3, b&lt;BR /&gt;3, b&lt;BR /&gt;3, d&lt;BR /&gt;;run;&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;by a;&lt;BR /&gt;retain flag;&lt;BR /&gt;if first.a then flag = 'N';&lt;BR /&gt;if b = 'b' then flag = 'Y';&lt;BR /&gt;if flag = 'N' then output;&lt;BR /&gt;drop flag;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2016 17:27:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dropping-observations-after-a-certain-value/m-p/244767#M268514</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2016-01-20T17:27:41Z</dc:date>
    </item>
    <item>
      <title>Re: Dropping observations after a certain value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dropping-observations-after-a-certain-value/m-p/244785#M268515</link>
      <description>&lt;P&gt;With the same requirements as for &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw﻿&lt;/a&gt;'s solution you could use a DO-&lt;STRONG&gt;UNTIL&lt;/STRONG&gt; loop:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
do until(last.A);
  set have;
  by A B notsorted;
  if ~flag then output;
  if B='b' &amp;amp; last.B then flag=1;
end;
drop flag;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For background information about this special usage of the DO-UNTIL loop ("DOW loop"), please see, for example, &lt;A href="http://www2.sas.com/proceedings/sugi28/099-28.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi28/099-28.pdf&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2016 18:26:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dropping-observations-after-a-certain-value/m-p/244785#M268515</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-01-20T18:26:04Z</dc:date>
    </item>
  </channel>
</rss>

