<?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: Removing duplicates based on two variables, but prioritizing based on a third variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-based-on-two-variables-but-prioritizing/m-p/587946#M167959</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;, both of your solutions worked and were actually what I had in mind at first. However, I was a bit hesitant because I wasn't sure if if first.index_date would remove just ANY duplicates of index_date. For example,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ID   index_date   priority
1    1/2/19           1
2    1/2/19           0&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I wouldn't want either rows to be removed, since the ID's are different, even though the index_date's are the same. Could you confirm this is the case? Thanks so much.&lt;/P&gt;</description>
    <pubDate>Wed, 11 Sep 2019 17:15:23 GMT</pubDate>
    <dc:creator>corkee</dc:creator>
    <dc:date>2019-09-11T17:15:23Z</dc:date>
    <item>
      <title>Removing duplicates based on two variables, but prioritizing based on a third variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-based-on-two-variables-but-prioritizing/m-p/587926#M167946</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to remove duplicates based on two variables: ID and index_date. I know one could easily use the following code to do this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=dsn nodupkey;
	by id index_date;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, for rows with duplicates of ID and index_date, I want prioritize one row over the others. For example, my dataset looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ID   index_date   priority
1    1/4/18           0
1    1/4/18           1
1    1/4/18           0&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I want to keep the row where priority = 1 and remove the ones priority = 0. How can I do this? Would sorting my data on ID, index_date, and descending priority first and then sorting by ID and index_date with nodupkey work?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2019 16:29:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-based-on-two-variables-but-prioritizing/m-p/587926#M167946</guid>
      <dc:creator>corkee</dc:creator>
      <dc:date>2019-09-11T16:29:55Z</dc:date>
    </item>
    <item>
      <title>Re: Removing duplicates based on two variables, but prioritizing based on a third variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-based-on-two-variables-but-prioritizing/m-p/587927#M167947</link>
      <description>&lt;P&gt;if you wanna subset only the records with priority=1, wouldn't it be a simple&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where priority=1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;in a datastep/sql?&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2019 16:36:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-based-on-two-variables-but-prioritizing/m-p/587927#M167947</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-09-11T16:36:29Z</dc:date>
    </item>
    <item>
      <title>Re: Removing duplicates based on two variables, but prioritizing based on a third variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-based-on-two-variables-but-prioritizing/m-p/587928#M167948</link>
      <description>&lt;P&gt;Hi, novinosrin. No, I don't want to ONLY keep observations where priority = 1. There might be non-duplicates where priority = 0, and I want to keep those too. I just want to make sure that for duplicates, the ones where priority = 1 is kept. Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2019 16:45:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-based-on-two-variables-but-prioritizing/m-p/587928#M167948</guid>
      <dc:creator>corkee</dc:creator>
      <dc:date>2019-09-11T16:45:40Z</dc:date>
    </item>
    <item>
      <title>Re: Removing duplicates based on two variables, but prioritizing based on a third variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-based-on-two-variables-but-prioritizing/m-p/587929#M167949</link>
      <description>&lt;P&gt;Can you please post a clear sample of what you "have" and what you "want"?&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2019 16:45:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-based-on-two-variables-but-prioritizing/m-p/587929#M167949</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-09-11T16:45:43Z</dc:date>
    </item>
    <item>
      <title>Re: Removing duplicates based on two variables, but prioritizing based on a third variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-based-on-two-variables-but-prioritizing/m-p/587934#M167953</link>
      <description>&lt;P&gt;I modified your sample&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID   index_date :mmddyy10.   priority;
format  index_date mmddyy10.;
cards;
1    1/4/18           0
1    1/4/18           1
1    1/4/18           0
1    1/6/18           0
1    1/6/18           0
1    1/6/18           0
;


proc sql;
create table want(drop=t) as
select *,count(distinct priority)&amp;gt;1 as t
from have
group by ID ,  index_date
having (t=1 and priority=1) or (t=0) ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Sep 2019 16:55:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-based-on-two-variables-but-prioritizing/m-p/587934#M167953</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-09-11T16:55:44Z</dc:date>
    </item>
    <item>
      <title>Re: Removing duplicates based on two variables, but prioritizing based on a third variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-based-on-two-variables-but-prioritizing/m-p/587935#M167954</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just tried your code, and unfortunately it did not give me the desired output.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi&amp;nbsp;@novinosrin,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That code didn't work, unfortunately. Let me try to provide a more concrete example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ID index_date priority
1 2/3/18 0
1 2/3/18 1
1 2/3/18 0
2 3/4/15 0
3 7/14/14 0
3 7/14/14 0
4 10/1/17 1&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;The desired dataset would keep the 2nd, 4th, 5th (or 6th, but not both), and the last row. The code you had provided kept both the 5th and the 6th rows. Thanks for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit: I think adding another code chunk would do the trick.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=want out=want2 nodupkey;
by id index_date;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Sep 2019 17:03:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-based-on-two-variables-but-prioritizing/m-p/587935#M167954</guid>
      <dc:creator>corkee</dc:creator>
      <dc:date>2019-09-11T17:03:28Z</dc:date>
    </item>
    <item>
      <title>Re: Removing duplicates based on two variables, but prioritizing based on a third variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-based-on-two-variables-but-prioritizing/m-p/587937#M167955</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/122635"&gt;@corkee&lt;/a&gt;&amp;nbsp; Thank you for clarifying. One last clarification, do you have many other variables or just that?&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2019 17:05:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-based-on-two-variables-but-prioritizing/m-p/587937#M167955</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-09-11T17:05:18Z</dc:date>
    </item>
    <item>
      <title>Re: Removing duplicates based on two variables, but prioritizing based on a third variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-based-on-two-variables-but-prioritizing/m-p/587940#M167956</link>
      <description>&lt;P&gt;Okay&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/122635"&gt;@corkee&lt;/a&gt;&amp;nbsp; I think this one should do&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID   index_date :mmddyy10.   priority;
format  index_date mmddyy10.;
cards;
1 2/3/18 0
1 2/3/18 1
1 2/3/18 0
2 3/4/15 0
3 7/14/14 0
3 7/14/14 0
4 10/1/17 1
;

proc sort data=have out=temp ;
by id index_date descending priority;
run;
data want;
set temp;
by id index_date;
if first.index_date;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Sep 2019 17:08:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-based-on-two-variables-but-prioritizing/m-p/587940#M167956</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-09-11T17:08:47Z</dc:date>
    </item>
    <item>
      <title>Re: Removing duplicates based on two variables, but prioritizing based on a third variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-based-on-two-variables-but-prioritizing/m-p/587942#M167957</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;, I have another variable that determines whether priority is = 1 or 0. I have to keep this variable for later uses. Thanks again!&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2019 17:09:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-based-on-two-variables-but-prioritizing/m-p/587942#M167957</guid>
      <dc:creator>corkee</dc:creator>
      <dc:date>2019-09-11T17:09:17Z</dc:date>
    </item>
    <item>
      <title>Re: Removing duplicates based on two variables, but prioritizing based on a third variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-based-on-two-variables-but-prioritizing/m-p/587944#M167958</link>
      <description>&lt;P&gt;If you want to use the NODUPKEY option on PROC SORT as the way to get to single observation per group then first sort them so the one you want to keep is first.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=dsn ;
  by id index_date descending priority ;
run;
proc sort data=dsn nodupkey;
  by id index_date ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you can replace the second PROC SORT with a simple data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dsn;
  set dsn ;
  by id index_date descending priority ;
  if first.index_date;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Sep 2019 17:10:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-based-on-two-variables-but-prioritizing/m-p/587944#M167958</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-09-11T17:10:22Z</dc:date>
    </item>
    <item>
      <title>Re: Removing duplicates based on two variables, but prioritizing based on a third variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-based-on-two-variables-but-prioritizing/m-p/587946#M167959</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;, both of your solutions worked and were actually what I had in mind at first. However, I was a bit hesitant because I wasn't sure if if first.index_date would remove just ANY duplicates of index_date. For example,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ID   index_date   priority
1    1/2/19           1
2    1/2/19           0&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I wouldn't want either rows to be removed, since the ID's are different, even though the index_date's are the same. Could you confirm this is the case? Thanks so much.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2019 17:15:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-based-on-two-variables-but-prioritizing/m-p/587946#M167959</guid>
      <dc:creator>corkee</dc:creator>
      <dc:date>2019-09-11T17:15:23Z</dc:date>
    </item>
    <item>
      <title>Re: Removing duplicates based on two variables, but prioritizing based on a third variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-based-on-two-variables-but-prioritizing/m-p/587949#M167960</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/122635"&gt;@corkee&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;, both of your solutions worked and were actually what I had in mind at first. However, I was a bit hesitant because I wasn't sure if if first.index_date would remove just ANY duplicates of index_date. For example,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ID   index_date   priority
1    1/2/19           1
2    1/2/19           0&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I wouldn't want either rows to be removed, since the ID's are different, even though the index_date's are the same. Could you confirm this is the case? Thanks so much.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;FIRST.INDEX_DATE means it is the first observation in the set of observations with the same values of ID and INDEX_DATE.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The FIRST.INDEX_DATE flag is not independent of the early variables in the BY statement. That would not make any sense and probably be impossible for SAS to even know how to calculate.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2019 17:19:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-based-on-two-variables-but-prioritizing/m-p/587949#M167960</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-09-11T17:19:17Z</dc:date>
    </item>
    <item>
      <title>Re: Removing duplicates based on two variables, but prioritizing based on a third variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-based-on-two-variables-but-prioritizing/m-p/587954#M167963</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;! You guys are great!&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2019 17:22:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-based-on-two-variables-but-prioritizing/m-p/587954#M167963</guid>
      <dc:creator>corkee</dc:creator>
      <dc:date>2019-09-11T17:22:12Z</dc:date>
    </item>
    <item>
      <title>Re: Removing duplicates based on two variables, but prioritizing based on a third variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-based-on-two-variables-but-prioritizing/m-p/587955#M167964</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/122635"&gt;@corkee&lt;/a&gt;&amp;nbsp;, Sir&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp; is of course absolutely better and experienced in explaining the functionality. From me, I would like increase the buffet menu by offering a Proc SQL&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want(drop=t) as
select distinct *,count(distinct priority)&amp;gt;1 as t
from have
group by ID ,  index_date
having t and priority=1 or t=0 ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2019 17:23:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-based-on-two-variables-but-prioritizing/m-p/587955#M167964</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-09-11T17:23:39Z</dc:date>
    </item>
    <item>
      <title>Re: Removing duplicates based on two variables, but prioritizing based on a third variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-based-on-two-variables-but-prioritizing/m-p/587965#M167966</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/122635"&gt;@corkee&lt;/a&gt;&amp;nbsp;, Sir&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp; is of course absolutely better and experienced in explaining the functionality. From me, I would like increase the buffet menu by offering a Proc SQL&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want(drop=t) as
select distinct *,count(distinct priority)&amp;gt;1 as t
from have
group by ID ,  index_date
having t and priority=1 or t=0 ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I am not sure how that is going to eliminate duplicates.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2019 17:33:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-based-on-two-variables-but-prioritizing/m-p/587965#M167966</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-09-11T17:33:41Z</dc:date>
    </item>
    <item>
      <title>Re: Removing duplicates based on two variables, but prioritizing based on a third variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-based-on-two-variables-but-prioritizing/m-p/587971#M167968</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A small test&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID   index_date :mmddyy10.   priority;
format  index_date mmddyy10.;
cards;
1 2/3/18 0
1 2/3/18 1
1 2/3/18 0
2 3/4/15 0
3 7/14/14 0
3 7/14/14 0
4 10/1/17 1
;


proc sql;
create table want(drop=t) as
select distinct *,count(distinct priority)&amp;gt;1 as t
from have
group by ID ,  index_date
having t and priority=1 or t=0 ;
quit;

proc print noobs;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV&gt;1 02/03/2018 1&lt;BR /&gt;2 03/04/2015 0&lt;BR /&gt;3 07/14/2014 0&lt;BR /&gt;4 10/01/2017 1&lt;/DIV&gt;
&lt;DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2019 17:49:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-based-on-two-variables-but-prioritizing/m-p/587971#M167968</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-09-11T17:49:35Z</dc:date>
    </item>
    <item>
      <title>Re: Removing duplicates based on two variables, but prioritizing based on a third variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-based-on-two-variables-but-prioritizing/m-p/587978#M167970</link>
      <description>&lt;P&gt;Your test data is too simple.&amp;nbsp; Just add one more variable, like a row number to see why.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;row+1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;ID index_date priority row&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;1 02/03/2018 1 2&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;2 03/04/2015 0 4&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" color="#FF0000"&gt;3 07/14/2014 0 5&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" color="#FF0000"&gt;3 07/14/2014 0 6&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;4 10/01/2017 1 7&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2019 18:17:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-based-on-two-variables-but-prioritizing/m-p/587978#M167970</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-09-11T18:17:13Z</dc:date>
    </item>
    <item>
      <title>Re: Removing duplicates based on two variables, but prioritizing based on a third variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-based-on-two-variables-but-prioritizing/m-p/587979#M167971</link>
      <description>&lt;P&gt;That's correct. The code assumes no more extra variables.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2019 18:18:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-based-on-two-variables-but-prioritizing/m-p/587979#M167971</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-09-11T18:18:27Z</dc:date>
    </item>
    <item>
      <title>Re: Removing duplicates based on two variables, but prioritizing based on a third variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-based-on-two-variables-but-prioritizing/m-p/587983#M167973</link>
      <description>&lt;P&gt;If there aren't any extra variables then just let the DISTINCT keyword to the work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
  select distinct *
  from have
  group by ID , index_date
  having priority=max(priority)
  order by ID , index_date
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Sep 2019 18:23:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-based-on-two-variables-but-prioritizing/m-p/587983#M167973</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-09-11T18:23:17Z</dc:date>
    </item>
    <item>
      <title>Re: Removing duplicates based on two variables, but prioritizing based on a third variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-based-on-two-variables-but-prioritizing/m-p/587989#M167976</link>
      <description>&lt;P&gt;Excellent catch. Afternoon drowsiness. Kudos!&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2019 18:53:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-duplicates-based-on-two-variables-but-prioritizing/m-p/587989#M167976</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-09-11T18:53:57Z</dc:date>
    </item>
  </channel>
</rss>

