<?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 values after multiple conditions in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-select-values-after-multiple-conditions/m-p/391430#M11852</link>
    <description>&lt;P&gt;Here is one way.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x; input id day timep results flag $; cards;
1  1   0     23       .
1  1   1     43      X
1  1   2     29      .             
1  1   3     14       .
2  1   0     17     .
2  1   1     32   .
2  1   2     54      X
2  1   3     59  .
; 
proc print;run;

data before;
set x(keep=flag);
if flag = 'X' then do;
   f = _n_ - 1;
   set x point=f;
   output;
   end;
run;
proc print; run;

data after;
set x(keep=flag) nobs=n;
if flag = 'X' and _n_ + 1 le n then do;
   f = _n_ + 1;
   set x point=f;
   output;
   end;
run;
proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 29 Aug 2017 11:53:26 GMT</pubDate>
    <dc:creator>WarrenKuhfeld</dc:creator>
    <dc:date>2017-08-29T11:53:26Z</dc:date>
    <item>
      <title>How to select values after multiple conditions</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-select-values-after-multiple-conditions/m-p/391415#M11851</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How I can select values after conditions inside multiple groups.&amp;nbsp;&lt;/P&gt;&lt;P&gt;My data looks like&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;id day timep results flag 
1  1   0     23       
1  1   1     43      X
1  1   2     29                   
1  1   3     14       
2  1   0     17     
2  1   1     32   
2  1   2     54      X
2  1   3     59      &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;How can I select values before X or after X inside the same ID.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example the wanted output would be like this for before X&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;id day timep results flag 
1  1   0     23  &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;and after X the results should be:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;1  1   2     29                   
1  1   3     14      &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;for id 1.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Aug 2017 09:29:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-select-values-after-multiple-conditions/m-p/391415#M11851</guid>
      <dc:creator>idaida</dc:creator>
      <dc:date>2017-08-29T09:29:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to select values after multiple conditions</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-select-values-after-multiple-conditions/m-p/391430#M11852</link>
      <description>&lt;P&gt;Here is one way.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x; input id day timep results flag $; cards;
1  1   0     23       .
1  1   1     43      X
1  1   2     29      .             
1  1   3     14       .
2  1   0     17     .
2  1   1     32   .
2  1   2     54      X
2  1   3     59  .
; 
proc print;run;

data before;
set x(keep=flag);
if flag = 'X' then do;
   f = _n_ - 1;
   set x point=f;
   output;
   end;
run;
proc print; run;

data after;
set x(keep=flag) nobs=n;
if flag = 'X' and _n_ + 1 le n then do;
   f = _n_ + 1;
   set x point=f;
   output;
   end;
run;
proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Aug 2017 11:53:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-select-values-after-multiple-conditions/m-p/391430#M11852</guid>
      <dc:creator>WarrenKuhfeld</dc:creator>
      <dc:date>2017-08-29T11:53:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to select values after multiple conditions</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-select-values-after-multiple-conditions/m-p/391436#M11853</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x; 
input id day timep results flag $; 
cards;
1  1   0     23       .
1  1   1     43      X
1  1   2     29      .             
1  1   3     14       .
2  1   0     17     .
2  1   1     32   .
2  1   2     54      X
2  1   3     59  .
; 
run;

data before after;
 set x;
 by id;
 retain found;
 if first.id then call missing(found);
 if flag='X' then found=1;
 if not found then output before;
  else if flag ne 'X' then output after;
  drop found;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Aug 2017 12:26:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-select-values-after-multiple-conditions/m-p/391436#M11853</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-08-29T12:26:15Z</dc:date>
    </item>
  </channel>
</rss>

