title: Duplicate data based on various conditions in SAS
body: <p>In the following data set I want to remove duplicates based on several conditions:</p>
  <p>For Auris disease:</p>
  <ul>
  <li>Same id, same condition (Auris), keep data with the first date only no matter what the date difference is.</li>
  </ul>
  <p>For other disease conditions (Acino and CRE):</p>
  <ul>
  <li><p>Same id, same condition, data difference more than 90 days keep data with the first date and last date if we have two dates.</p>
  </li>
  <li><p>Same id, same condition, data difference more than 90 days keep data with the first date and last date if we have three dates or more.
  Keep all three if the difference is more than 90 days between 1st and second, and more than 90 days between 2nd and third dates.</p>
  <pre><code>data have;
  input Id  Disease $ Date :mmddyy10.;
  format date mmddyy10.;
  datalines;
  123   Auris   01/01/2021
  123   CRE     09/02/2020
  344   CRE     08/06/2019
  344   CRE     03/06/2020
  344   CRE     03/03/2021
  323   CRE     01/06/2019
  323   CRE     09/06/2020
  323   CRE     09/09/2020
  167   Acino   03/06/2020
  167   Acino   03/19/2020
  167   Acino   09/03/2021
  256   Auris   08/05/2020
  256   Auris   10/07/2021
  317   Acino   12/07/2018
  317   Acino   01/03/2018
  ;;;;
  run;
  </code></pre>
  </li>
  </ul>
  <p>Result should be as this:</p>
  <pre><code>  123   Auris   01/01/2021
    123   CRE     09/02/2020
    344   CRE     08/06/2019
    344   CRE     03/06/2020
    344   CRE     03/03/2021
    323   CRE     01/06/2019
    323   CRE     09/06/2020
    167   Acino   03/06/2020
    167   Acino   09/03/2021
    256   Auris   08/05/2020
    256   Auris   10/07/2021
    317   Acino   12/07/2018
    
  </code></pre>
  <p>Thanks</p>