<?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: Flagging Records Based on Date Criteria in SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Flagging-Records-Based-on-Date-Criteria-in-SAS/m-p/934367#M367422</link>
    <description>&lt;P&gt;Run a double DO loop:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
do until (last.id);
  set have (where=(tp_2 = 0));
  by id;
end;
ref = date;
do until (last.id);
  set have;
  by id;
  flag = (tp_2 = 0 and intck("month",date,ref,"s") le 10);
  output;
end;
drop ref;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Assumes that&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;have is sorted by id and date&lt;/LI&gt;
&lt;LI&gt;there is at least one tp_2 = 0 for every id&lt;/LI&gt;
&lt;/UL&gt;</description>
    <pubDate>Tue, 02 Jul 2024 07:56:40 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2024-07-02T07:56:40Z</dc:date>
    <item>
      <title>Flagging Records Based on Date Criteria in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-Records-Based-on-Date-Criteria-in-SAS/m-p/934348#M367412</link>
      <description>&lt;P&gt;I have a dataset &lt;CODE&gt;have&lt;/CODE&gt; with variables &lt;CODE&gt;id&lt;/CODE&gt;, &lt;CODE&gt;date_var&lt;/CODE&gt;, and &lt;CODE&gt;tp_2&lt;/CODE&gt;. I need to flag records where &lt;CODE&gt;tp_2 = 0&lt;/CODE&gt;. For multiple records with the same &lt;CODE&gt;id&lt;/CODE&gt;, I want to use the last occurring &lt;CODE&gt;date_var&lt;/CODE&gt; for each &lt;CODE&gt;id&lt;/CODE&gt; to check if other records with the same &lt;CODE&gt;id&lt;/CODE&gt; are within 10 months of this date. If they are within 10 months, they should be flagged.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
    informat id $20. date_var date9.;
    format date_var date9. tp_2 1.;
    input id $ date_var tp_2;
    datalines;
23417 09May2021 0
23417 25Jul2022 0
23417 01Aug2022 0
27539 12Oct2021 0
27539 03Nov2021 0
73830 19Nov2021 0
;
run;&lt;BR /&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;data want;
    informat id $20. date_var date9.;
    format date_var date9. tp_2 1. flag 1.;
    input id $ date_var tp_2 flag;
    datalines;
23417 09May2021 0  0
23417 25Jul2022 0  1
23417 01Aug2022 0  0
27539 12Oct2021 0  1
27539 03Nov2021 0  0
73830 19Nov2021 0  0
;
run;
&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2024 21:42:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-Records-Based-on-Date-Criteria-in-SAS/m-p/934348#M367412</guid>
      <dc:creator>SP01</dc:creator>
      <dc:date>2024-07-01T21:42:26Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging Records Based on Date Criteria in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-Records-Based-on-Date-Criteria-in-SAS/m-p/934365#M367420</link>
      <description>&lt;P&gt;Is the data sorted by id and date_var?&lt;/P&gt;
&lt;P&gt;Are there any obs with tp_2 ^= 0 in your data?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=work.have nway;
    class id;
    var date_var;
    output out=work.last(drop= _type_ _freq_) max=last_date;
run;

data work.want;
    merge work.have work.last;
    by id;
    
    n = intck("month", date_var, last_date, 'd');
    flag = (not last.id) and n &amp;lt;= 10;
    
    drop n last_date;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Jul 2024 09:01:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-Records-Based-on-Date-Criteria-in-SAS/m-p/934365#M367420</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2024-07-02T09:01:04Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging Records Based on Date Criteria in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-Records-Based-on-Date-Criteria-in-SAS/m-p/934367#M367422</link>
      <description>&lt;P&gt;Run a double DO loop:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
do until (last.id);
  set have (where=(tp_2 = 0));
  by id;
end;
ref = date;
do until (last.id);
  set have;
  by id;
  flag = (tp_2 = 0 and intck("month",date,ref,"s") le 10);
  output;
end;
drop ref;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Assumes that&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;have is sorted by id and date&lt;/LI&gt;
&lt;LI&gt;there is at least one tp_2 = 0 for every id&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Tue, 02 Jul 2024 07:56:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-Records-Based-on-Date-Criteria-in-SAS/m-p/934367#M367422</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-07-02T07:56:40Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging Records Based on Date Criteria in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-Records-Based-on-Date-Criteria-in-SAS/m-p/934526#M367490</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;Yes, there are observations where tp_2^= 0 in the data.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jul 2024 08:31:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-Records-Based-on-Date-Criteria-in-SAS/m-p/934526#M367490</guid>
      <dc:creator>SP01</dc:creator>
      <dc:date>2024-07-03T08:31:26Z</dc:date>
    </item>
  </channel>
</rss>

