<?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 first row meeting value, if not last row per id in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Selecting-first-row-meeting-value-if-not-last-row-per-id/m-p/768182#M243630</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After sorting by date and ID, I am trying to select the first row per id that meets a certain criteria (x &amp;gt; 1), but if none of the rows (per id)&amp;nbsp; meet this criteria, I want to select the last row for that id?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I appreciate any help, thanks.&lt;/P&gt;&lt;P&gt;Natalia&lt;/P&gt;</description>
    <pubDate>Thu, 16 Sep 2021 19:30:11 GMT</pubDate>
    <dc:creator>nataliavanessa0</dc:creator>
    <dc:date>2021-09-16T19:30:11Z</dc:date>
    <item>
      <title>Selecting first row meeting value, if not last row per id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-first-row-meeting-value-if-not-last-row-per-id/m-p/768182#M243630</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After sorting by date and ID, I am trying to select the first row per id that meets a certain criteria (x &amp;gt; 1), but if none of the rows (per id)&amp;nbsp; meet this criteria, I want to select the last row for that id?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I appreciate any help, thanks.&lt;/P&gt;&lt;P&gt;Natalia&lt;/P&gt;</description>
      <pubDate>Thu, 16 Sep 2021 19:30:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-first-row-meeting-value-if-not-last-row-per-id/m-p/768182#M243630</guid>
      <dc:creator>nataliavanessa0</dc:creator>
      <dc:date>2021-09-16T19:30:11Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting first row meeting value, if not last row per id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-first-row-meeting-value-if-not-last-row-per-id/m-p/768189#M243632</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by ID;
*hold value of flag across rows;
retain flag;

*initialize flag to 0 at start of each ID;
if first.id then flag=0;

*check if x &amp;gt;1 and flag is not 0 - has not happened before;
if x&amp;gt;1 and flag ne 1 then do;
    *set flag so you know it has been found;
   flag=1;
   *output record to dataset;
   output;

end;

*if last of the ID and flag is still 0 then output as well;
if last.id and flag=0 then output;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/123632"&gt;@nataliavanessa0&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After sorting by date and ID, I am trying to select the first row per id that meets a certain criteria (x &amp;gt; 1), but if none of the rows (per id)&amp;nbsp; meet this criteria, I want to select the last row for that id?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I appreciate any help, thanks.&lt;/P&gt;
&lt;P&gt;Natalia&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Sep 2021 20:36:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-first-row-meeting-value-if-not-last-row-per-id/m-p/768189#M243632</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-09-16T20:36:11Z</dc:date>
    </item>
  </channel>
</rss>

