<?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 exclude or delete observations with if then statement? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-exclude-or-delete-observations-with-if-then-statement/m-p/893049#M352768</link>
    <description>&lt;P&gt;Sort data first using name and descending date, then select the first.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by name descending date;
run;

data want;
set have;
by name descending date;
if first.name and rank=1 and status='P1';
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 06 Sep 2023 22:30:42 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2023-09-06T22:30:42Z</dc:date>
    <item>
      <title>How to exclude or delete observations with if then statement?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-exclude-or-delete-observations-with-if-then-statement/m-p/893048#M352767</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have multiple observations with the same names with ranks and dates. I basically want to exclude names where if their date is less than their other date with their rank. For example Bob has multiple dates with his name, however, for one date (1/2/23) and he is ranked 1 with a status of P1. There is another row/date for Bob (1/2/22) where he is ranked 2 with a status of M1. The Rank 1 and P1 are my conditions for a top rank.&amp;nbsp; Therefore, because Bob's date is 1/2/22 in one of the rows and he is rank 2 with a status of M1 then I want to exclude that row. Below are 2 tables of what I have and what I want along with a code. Please let me know whats the best way to approach this as im still learning. Thank you.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;Data Want;
set Have;

*just how im thinking but dont know how to code it;

If date is &amp;lt; date where Rank=1 and Status=P1
Run;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;EM&gt;Have&lt;/EM&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Name&lt;/TD&gt;&lt;TD&gt;Date&lt;/TD&gt;&lt;TD&gt;Rank&lt;/TD&gt;&lt;TD&gt;Status&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;BOB&lt;/TD&gt;&lt;TD&gt;1/2/23&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;P1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;BOB&lt;/TD&gt;&lt;TD&gt;1/2/22&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;M1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Want&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Name&lt;/TD&gt;&lt;TD&gt;Date&lt;/TD&gt;&lt;TD&gt;Rank&lt;/TD&gt;&lt;TD&gt;Status&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;BOB&lt;/TD&gt;&lt;TD&gt;1/2/23&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;P1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Wed, 06 Sep 2023 21:55:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-exclude-or-delete-observations-with-if-then-statement/m-p/893048#M352767</guid>
      <dc:creator>rebelde52</dc:creator>
      <dc:date>2023-09-06T21:55:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to exclude or delete observations with if then statement?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-exclude-or-delete-observations-with-if-then-statement/m-p/893049#M352768</link>
      <description>&lt;P&gt;Sort data first using name and descending date, then select the first.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by name descending date;
run;

data want;
set have;
by name descending date;
if first.name and rank=1 and status='P1';
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Sep 2023 22:30:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-exclude-or-delete-observations-with-if-then-statement/m-p/893049#M352768</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-09-06T22:30:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to exclude or delete observations with if then statement?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-exclude-or-delete-observations-with-if-then-statement/m-p/893050#M352769</link>
      <description>&lt;P&gt;If your selection rule is simply picking the top rank then try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Want;
set Have;
where Rank='1' and Status='P1';
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Sep 2023 22:34:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-exclude-or-delete-observations-with-if-then-statement/m-p/893050#M352769</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-09-06T22:34:14Z</dc:date>
    </item>
  </channel>
</rss>

