<?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 revoming duplicate using proc sql when there is a certain rule. in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/revoming-duplicate-using-proc-sql-when-there-is-a-certain-rule/m-p/236858#M6097</link>
    <description>&lt;P&gt;Hi everyone,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I have a data like this.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data t;INPUT id dis;cards;&lt;BR /&gt;1 0&lt;BR /&gt;1 1&lt;BR /&gt;2 0&lt;BR /&gt;3 1&lt;BR /&gt;3 0&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is a duplicate when ID = 1 and 3.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to remove them but keep the dis status is 1.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can do to by sorting the data by ID and descending the variable of dis. Then I can use the proc sort with nodupkey statement to keep the first id in the data set.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, I want to learn how to do it by Proc SQL.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I try use the following syntax.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql; select distinct ID, dis from t HAVING dis=1; quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But, it turns out that the observation 2 is not included because its dis status= 0.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Further, how to do that when there are more complex relationships and more variables?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, if there are two rule.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data t;INPUT id dis exp;cards;&lt;BR /&gt;1 0 1&lt;BR /&gt;1 1 2&lt;BR /&gt;2 0 3&lt;BR /&gt;3 1 4&lt;BR /&gt;3 0 5&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to pic up the distinct ID when Dis stautus = 1 and Exp status = 2,3,4.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone tell me how to do?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thx.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 29 Nov 2015 21:55:13 GMT</pubDate>
    <dc:creator>ffgsdf</dc:creator>
    <dc:date>2015-11-29T21:55:13Z</dc:date>
    <item>
      <title>revoming duplicate using proc sql when there is a certain rule.</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/revoming-duplicate-using-proc-sql-when-there-is-a-certain-rule/m-p/236858#M6097</link>
      <description>&lt;P&gt;Hi everyone,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I have a data like this.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data t;INPUT id dis;cards;&lt;BR /&gt;1 0&lt;BR /&gt;1 1&lt;BR /&gt;2 0&lt;BR /&gt;3 1&lt;BR /&gt;3 0&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is a duplicate when ID = 1 and 3.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to remove them but keep the dis status is 1.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can do to by sorting the data by ID and descending the variable of dis. Then I can use the proc sort with nodupkey statement to keep the first id in the data set.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, I want to learn how to do it by Proc SQL.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I try use the following syntax.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql; select distinct ID, dis from t HAVING dis=1; quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But, it turns out that the observation 2 is not included because its dis status= 0.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Further, how to do that when there are more complex relationships and more variables?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, if there are two rule.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data t;INPUT id dis exp;cards;&lt;BR /&gt;1 0 1&lt;BR /&gt;1 1 2&lt;BR /&gt;2 0 3&lt;BR /&gt;3 1 4&lt;BR /&gt;3 0 5&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to pic up the distinct ID when Dis stautus = 1 and Exp status = 2,3,4.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone tell me how to do?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thx.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 29 Nov 2015 21:55:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/revoming-duplicate-using-proc-sql-when-there-is-a-certain-rule/m-p/236858#M6097</guid>
      <dc:creator>ffgsdf</dc:creator>
      <dc:date>2015-11-29T21:55:13Z</dc:date>
    </item>
    <item>
      <title>Re: revoming duplicate using proc sql when there is a certain rule.</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/revoming-duplicate-using-proc-sql-when-there-is-a-certain-rule/m-p/236862#M6098</link>
      <description>&lt;P&gt;In your simple case your sql should like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table want as
  select distinct id, dis
  from t
  group by id
  having dis = max(dis);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But for the more complicated examples you describe, the sql would get pretty ugly and, and&amp;nbsp;I understand you're keen to explore sql,&amp;nbsp;its really not the best option.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sort and Data step is the simplest:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=t ;
  by id descending dis descending exp;
run; 
data want;
  set t;
  by id;
  if first.id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 29 Nov 2015 23:03:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/revoming-duplicate-using-proc-sql-when-there-is-a-certain-rule/m-p/236862#M6098</guid>
      <dc:creator>JerryLeBreton</dc:creator>
      <dc:date>2015-11-29T23:03:33Z</dc:date>
    </item>
  </channel>
</rss>

