<?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: Compare dates and check if an event occurs within &amp;quot;n&amp;quot; days in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Compare-dates-and-check-if-an-event-occurs-within-quot-n-quot/m-p/944397#M42433</link>
    <description>&lt;P&gt;Double DOW-loop should do the job:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DB;
  input ID :$20. Admission :date09. Discharge :date09. Influenza_pathogen Death;
  format Admission date9. Discharge date9.;
cards;
0001  13JAN2017 25JAN2017  1   0
0001  22FEB2018 03MAR2018  0   0
0001  30JAN2019 04MAR2019  0   0
0002  01DEC2016 14DEC2016  0   0
0002  01DEC2016 14DEC2016  0   0
0002  25DEC2017 02JAN2018  1   0
0002  06JAN2018 09JAN2018  0   1
0003  09JAN2016 25JAN2016  1   1
0004  29JAN2018 12FEB2018  1   0
0004  29JAN2018 12FEB2018  0   0
0004  25FEB2018 26FEB2018  0   1
0004  25FEB2018 26FEB2018  0   0
;run;

proc print;
run;

data want;
  do until(last.ID);
    set DB;
    by ID;
    if Death then death_dt=Discharge;
  end;

  do until(last.ID);
    set DB;
    by ID;
    if death_dt then 
      do;
        if Influenza_pathogen = 1 then XXX+(abs(Discharge-death_dt)&amp;lt;30);
      end;
    Index_death = death AND XXX;
    output;
  end;
  call missing(of _all_);
  drop death_dt XXX; 
run;

proc print;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 18 Sep 2024 12:54:20 GMT</pubDate>
    <dc:creator>yabwon</dc:creator>
    <dc:date>2024-09-18T12:54:20Z</dc:date>
    <item>
      <title>Compare dates and check if an event occurs within "n" days</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Compare-dates-and-check-if-an-event-occurs-within-quot-n-quot/m-p/944387#M42429</link>
      <description>&lt;P&gt;Hi guys,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;suppose to have the following dataset:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DB;
  input ID :$20. Admission :date09. Discharge :date09. Influenza_pathogen Death;
  format Admission date9. Discharge date9.;
cards;
0001  13JAN2017 25JAN2017  1   0
0001  22FEB2018 03MAR2018  0   0
0001  30JAN2019 04MAR2019  0   0
0002  01DEC2016 14DEC2016  0   0
0002  01DEC2016 14DEC2016  0   0
0002  25DEC2017 02JAN2018  1   0
0002  06JAN2018 09JAN2018  0   1
0003  09JAN2016 25JAN2016  1   1
0004  29JAN2018 12FEB2018  1   0
0004  29JAN2018 12FEB2018  0   0
0004  25FEB2018 26FEB2018  0   1
0004  25FEB2018 26FEB2018  0   0
;run;

Is there a way to get the following new dataset? 


data D1;
  input ID :$20. Admission :date09. Discharge :date09. Influenza_pathogen Death Index_death;
  format Admission date9. Discharge date9.;
cards;
0001  13JAN2017 25JAN2017  1   0   0
0001  22FEB2018 03MAR2018  0   0   0
0001  30JAN2019 04MAR2019  0   0   0
0002  01DEC2016 14DEC2016  0   0   0
0002  01DEC2016 14DEC2016  0   0   0
0002  25DEC2017 02JAN2018  1   0   0
0002  06JAN2018 09JAN2018  0   1   1
0003  09JAN2016 25JAN2016  1   1   1
0004  29JAN2018 12FEB2018  1   0   0
0004  29JAN2018 12FEB2018  0   0   0
0004  25FEB2018 26FEB2018  0   1   1
0004  25FEB2018 26FEB2018  0   0   0
;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In other words if death (death = 1) occurs within 30 days from the date (discharge!) where influenza_pathogen = 1 (meaning an admission for influenza occurred at that date) than Index_death = 1. Note that some dates are repeated but not influenza pathogen and death indexes (e.g.,&amp;nbsp;&lt;CODE class=" language-sas"&gt;0004  29JAN2018 12FEB2018 and&amp;nbsp;&lt;/CODE&gt; &lt;CODE class=" language-sas"&gt;0004  25FEB2018 26FEB2018&lt;/CODE&gt;). This should be maintained also for Index_death.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: when comparing dates please consider always &lt;U&gt;discharge&lt;/U&gt; date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Sep 2024 12:06:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Compare-dates-and-check-if-an-event-occurs-within-quot-n-quot/m-p/944387#M42429</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2024-09-18T12:06:58Z</dc:date>
    </item>
    <item>
      <title>Re: Compare dates and check if an event occurs within "n" days</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Compare-dates-and-check-if-an-event-occurs-within-quot-n-quot/m-p/944397#M42433</link>
      <description>&lt;P&gt;Double DOW-loop should do the job:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DB;
  input ID :$20. Admission :date09. Discharge :date09. Influenza_pathogen Death;
  format Admission date9. Discharge date9.;
cards;
0001  13JAN2017 25JAN2017  1   0
0001  22FEB2018 03MAR2018  0   0
0001  30JAN2019 04MAR2019  0   0
0002  01DEC2016 14DEC2016  0   0
0002  01DEC2016 14DEC2016  0   0
0002  25DEC2017 02JAN2018  1   0
0002  06JAN2018 09JAN2018  0   1
0003  09JAN2016 25JAN2016  1   1
0004  29JAN2018 12FEB2018  1   0
0004  29JAN2018 12FEB2018  0   0
0004  25FEB2018 26FEB2018  0   1
0004  25FEB2018 26FEB2018  0   0
;run;

proc print;
run;

data want;
  do until(last.ID);
    set DB;
    by ID;
    if Death then death_dt=Discharge;
  end;

  do until(last.ID);
    set DB;
    by ID;
    if death_dt then 
      do;
        if Influenza_pathogen = 1 then XXX+(abs(Discharge-death_dt)&amp;lt;30);
      end;
    Index_death = death AND XXX;
    output;
  end;
  call missing(of _all_);
  drop death_dt XXX; 
run;

proc print;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Sep 2024 12:54:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Compare-dates-and-check-if-an-event-occurs-within-quot-n-quot/m-p/944397#M42433</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2024-09-18T12:54:20Z</dc:date>
    </item>
    <item>
      <title>Re: Compare dates and check if an event occurs within "n" days</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Compare-dates-and-check-if-an-event-occurs-within-quot-n-quot/m-p/944398#M42434</link>
      <description>&lt;P&gt;You coulc use retain to retain the dischage date where&amp;nbsp;Influenza_pathogen=1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input ID :$20. Admission :date09. Discharge :date09. Influenza_pathogen Death;
  format Admission date9. Discharge date9.;
cards;
0001  13JAN2017 25JAN2017  1   0
0001  22FEB2018 03MAR2018  0   0
0001  30JAN2019 04MAR2019  0   0
0002  01DEC2016 14DEC2016  0   0
0002  01DEC2016 14DEC2016  0   0
0002  25DEC2017 02JAN2018  1   0
0002  06JAN2018 09JAN2018  0   1
0003  09JAN2016 25JAN2016  1   1
0004  29JAN2018 12FEB2018  1   0
0004  29JAN2018 12FEB2018  0   0
0004  25FEB2018 26FEB2018  0   1
0004  25FEB2018 26FEB2018  0   0
;run;


data want;
set have;
retain influenza_discharge;
if Influenza_pathogen then influenza_discharge=Discharge;
if death=1 and Discharge-influenza_discharge&amp;lt;=30 then Index_death=1;
else Index_death=0;
drop influenza_discharge;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Sep 2024 12:54:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Compare-dates-and-check-if-an-event-occurs-within-quot-n-quot/m-p/944398#M42434</guid>
      <dc:creator>rudfaden</dc:creator>
      <dc:date>2024-09-18T12:54:25Z</dc:date>
    </item>
  </channel>
</rss>

