<?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 Deleting by ID with multiple conditions and date differences. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Deleting-by-ID-with-multiple-conditions-and-date-differences/m-p/803972#M316589</link>
    <description>&lt;P&gt;Hi again,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 1 rule: If Z occurs within 30 days before A or B on any var1,2,3 then remove all rows with that id. In this example persons 1 and 4 will remain, and 2 and 3 are removed. I'm having trouble with combining syntax for date comparisons and syntax for multiple conditions.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;DATA have;&lt;BR /&gt;input id date mmddyy10. var1 $ var2 $ var3 $ ;&lt;BR /&gt;format date mmddyy10.;&lt;BR /&gt;CARDS;&lt;BR /&gt;1 09/21/2016 B D D&lt;BR /&gt;1 09/28/2016 B D D&lt;BR /&gt;1 10/11/2016 Z . .&lt;BR /&gt;2 01/14/2016 D Z .&lt;BR /&gt;2 01/15/2016 Z D D&lt;BR /&gt;2 02/09/2016 A . .&lt;BR /&gt;3 09/20/2019 Z D .&lt;BR /&gt;3 10/02/2019 A . .&lt;BR /&gt;3 10/24/2019 A . .&lt;BR /&gt;4 09/01/2017 A . .&lt;BR /&gt;4 09/07/2017 Z . .&lt;BR /&gt;4 10/10/2017 A . .&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA want;&lt;BR /&gt;input id date mmddyy10. var1 $ var2 $ var3 $ ;&lt;BR /&gt;format date mmddyy10.;&lt;BR /&gt;CARDS;&lt;BR /&gt;1 09/21/2016 B D D&lt;BR /&gt;1 09/28/2016 B D D&lt;BR /&gt;1 10/11/2016 Z . .&lt;BR /&gt;4 09/01/2017 A . .&lt;BR /&gt;4 09/07/2017 Z . .&lt;BR /&gt;4 10/10/2017 A . .&lt;BR /&gt;;&lt;BR /&gt;run;&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>Fri, 25 Mar 2022 04:49:49 GMT</pubDate>
    <dc:creator>Manhort</dc:creator>
    <dc:date>2022-03-25T04:49:49Z</dc:date>
    <item>
      <title>Deleting by ID with multiple conditions and date differences.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-by-ID-with-multiple-conditions-and-date-differences/m-p/803972#M316589</link>
      <description>&lt;P&gt;Hi again,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 1 rule: If Z occurs within 30 days before A or B on any var1,2,3 then remove all rows with that id. In this example persons 1 and 4 will remain, and 2 and 3 are removed. I'm having trouble with combining syntax for date comparisons and syntax for multiple conditions.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;DATA have;&lt;BR /&gt;input id date mmddyy10. var1 $ var2 $ var3 $ ;&lt;BR /&gt;format date mmddyy10.;&lt;BR /&gt;CARDS;&lt;BR /&gt;1 09/21/2016 B D D&lt;BR /&gt;1 09/28/2016 B D D&lt;BR /&gt;1 10/11/2016 Z . .&lt;BR /&gt;2 01/14/2016 D Z .&lt;BR /&gt;2 01/15/2016 Z D D&lt;BR /&gt;2 02/09/2016 A . .&lt;BR /&gt;3 09/20/2019 Z D .&lt;BR /&gt;3 10/02/2019 A . .&lt;BR /&gt;3 10/24/2019 A . .&lt;BR /&gt;4 09/01/2017 A . .&lt;BR /&gt;4 09/07/2017 Z . .&lt;BR /&gt;4 10/10/2017 A . .&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA want;&lt;BR /&gt;input id date mmddyy10. var1 $ var2 $ var3 $ ;&lt;BR /&gt;format date mmddyy10.;&lt;BR /&gt;CARDS;&lt;BR /&gt;1 09/21/2016 B D D&lt;BR /&gt;1 09/28/2016 B D D&lt;BR /&gt;1 10/11/2016 Z . .&lt;BR /&gt;4 09/01/2017 A . .&lt;BR /&gt;4 09/07/2017 Z . .&lt;BR /&gt;4 10/10/2017 A . .&lt;BR /&gt;;&lt;BR /&gt;run;&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>Fri, 25 Mar 2022 04:49:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-by-ID-with-multiple-conditions-and-date-differences/m-p/803972#M316589</guid>
      <dc:creator>Manhort</dc:creator>
      <dc:date>2022-03-25T04:49:49Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting by ID with multiple conditions and date differences.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-by-ID-with-multiple-conditions-and-date-differences/m-p/803999#M316597</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA have;
input id date mmddyy10. var1 $ var2 $ var3 $ ;
format date mmddyy10.;
CARDS;
1 09/21/2016 B D D
1 09/28/2016 B D D
1 10/11/2016 Z . .
2 01/14/2016 D Z .
2 01/15/2016 Z D D
2 02/09/2016 A . .
3 09/20/2019 Z D .
3 10/02/2019 A . .
3 10/24/2019 A . .
4 09/01/2017 A . .
4 09/07/2017 Z . .
4 10/10/2017 A . .
;
run;

data want(drop = d1 - d3 c);
   do until (last.id);
      set have;
      by id;
      array v var:;
      array d d1 - d3;
      
      do over v;
         if v = 'Z' then d = date;
         if v in ('A', 'B') and c = . then c = range(date, d);
      end;
   end;

   do until (last.id);
      set have;
      by id;
      if c = 0 | c &amp;gt; 30 then output;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Result:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;id  date        var1  var2  var3 
1   09/21/2016  B     D     D 
1   09/28/2016  B     D     D 
1   10/11/2016  Z             
4   09/01/2017  A             
4   09/07/2017  Z             
4   10/10/2017  A            &lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2022 08:25:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-by-ID-with-multiple-conditions-and-date-differences/m-p/803999#M316597</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-03-25T08:25:21Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting by ID with multiple conditions and date differences.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-by-ID-with-multiple-conditions-and-date-differences/m-p/804035#M316607</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA have;
input id date mmddyy10. var1 $ var2 $ var3 $ ;
format date mmddyy10.;
CARDS;
1 09/21/2016 B D D
1 09/28/2016 B D D
1 10/11/2016 Z . .
2 01/14/2016 D Z .
2 01/15/2016 Z D D
2 02/09/2016 A . .
3 09/20/2019 Z D .
3 10/02/2019 A . .
3 10/24/2019 A . .
4 09/01/2017 A . .
4 09/07/2017 Z . .
4 10/10/2017 A . .
;
run;

data temp;
 set have;
 by id;
 dif=dif(date);
 if first.id then call missing(dif);
run;

data id;
 set temp;
 if .&amp;lt;dif&amp;lt;30 and ( 
  (var1 in ('A' 'B') and lag(var1)='Z') or
  (var2 in ('A' 'B') and lag(var2)='Z') or 
  (var3 in ('A' 'B') and lag(var3)='Z')   ) ;
run;

proc sql;
create table want as
select * from have where id not in (select id from id);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Mar 2022 12:10:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-by-ID-with-multiple-conditions-and-date-differences/m-p/804035#M316607</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-03-25T12:10:51Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting by ID with multiple conditions and date differences.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-by-ID-with-multiple-conditions-and-date-differences/m-p/804142#M316636</link>
      <description>This one did the trick! Thanks!</description>
      <pubDate>Fri, 25 Mar 2022 17:06:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-by-ID-with-multiple-conditions-and-date-differences/m-p/804142#M316636</guid>
      <dc:creator>Manhort</dc:creator>
      <dc:date>2022-03-25T17:06:02Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting by ID with multiple conditions and date differences.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-by-ID-with-multiple-conditions-and-date-differences/m-p/804154#M316640</link>
      <description>&lt;P&gt;Anytime &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2022 18:04:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-by-ID-with-multiple-conditions-and-date-differences/m-p/804154#M316640</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-03-25T18:04:53Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting by ID with multiple conditions and date differences.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-by-ID-with-multiple-conditions-and-date-differences/m-p/805426#M317277</link>
      <description>Hey &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;, did you edit this post at all? Maybe changed a 'd4' to 'd3' on this line:&lt;BR /&gt;&lt;BR /&gt;array d d1 - d3;</description>
      <pubDate>Fri, 01 Apr 2022 02:32:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-by-ID-with-multiple-conditions-and-date-differences/m-p/805426#M317277</guid>
      <dc:creator>Manhort</dc:creator>
      <dc:date>2022-04-01T02:32:36Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting by ID with multiple conditions and date differences.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-by-ID-with-multiple-conditions-and-date-differences/m-p/805477#M317303</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/417971"&gt;@Manhort&lt;/a&gt;&amp;nbsp;, I don't understand the question?&lt;/P&gt;</description>
      <pubDate>Fri, 01 Apr 2022 10:51:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-by-ID-with-multiple-conditions-and-date-differences/m-p/805477#M317303</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-04-01T10:51:10Z</dc:date>
    </item>
  </channel>
</rss>

