<?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 Episode identification with conditions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Episode-identification-with-conditions/m-p/638918#M190012</link>
    <description>&lt;P&gt;Dear SAS community,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am having the following problem:&amp;nbsp;&lt;/P&gt;&lt;P&gt;My dataset has 3 variables: date, sample, episode. Now I want to reduce the dataset so that I only have the episodes when a sample was taken. A definition of an episode is that there are 3 days before and after without an Episode (E=0). So in the following example I only want the data from 05/01-09/01 because this will be my episode for the sample that was taken on 05/01/20. There is one day which is not qualifying for E=1 but that doesnt matter because it is within the episode. I hope it is somehow clear what I mean.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance for your help.&lt;/P&gt;&lt;P&gt;Bianca&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data WORK.CLASS;&lt;BR /&gt;input date sample episode;&lt;BR /&gt;datalines;&lt;BR /&gt;010120 0 0&lt;BR /&gt;020120 0 0&lt;BR /&gt;030120 0 0&lt;BR /&gt;040120 0 0&lt;BR /&gt;050120 1 1&lt;BR /&gt;060120 0 1&lt;BR /&gt;070120 0 1&lt;BR /&gt;080120 0 0&lt;BR /&gt;090120 0 1&lt;BR /&gt;100120 0 0&lt;BR /&gt;110120 0 0&lt;BR /&gt;120120 0 0&lt;BR /&gt;130120 0 0&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 10 Apr 2020 12:41:27 GMT</pubDate>
    <dc:creator>Bianca1610</dc:creator>
    <dc:date>2020-04-10T12:41:27Z</dc:date>
    <item>
      <title>Episode identification with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Episode-identification-with-conditions/m-p/638918#M190012</link>
      <description>&lt;P&gt;Dear SAS community,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am having the following problem:&amp;nbsp;&lt;/P&gt;&lt;P&gt;My dataset has 3 variables: date, sample, episode. Now I want to reduce the dataset so that I only have the episodes when a sample was taken. A definition of an episode is that there are 3 days before and after without an Episode (E=0). So in the following example I only want the data from 05/01-09/01 because this will be my episode for the sample that was taken on 05/01/20. There is one day which is not qualifying for E=1 but that doesnt matter because it is within the episode. I hope it is somehow clear what I mean.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance for your help.&lt;/P&gt;&lt;P&gt;Bianca&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data WORK.CLASS;&lt;BR /&gt;input date sample episode;&lt;BR /&gt;datalines;&lt;BR /&gt;010120 0 0&lt;BR /&gt;020120 0 0&lt;BR /&gt;030120 0 0&lt;BR /&gt;040120 0 0&lt;BR /&gt;050120 1 1&lt;BR /&gt;060120 0 1&lt;BR /&gt;070120 0 1&lt;BR /&gt;080120 0 0&lt;BR /&gt;090120 0 1&lt;BR /&gt;100120 0 0&lt;BR /&gt;110120 0 0&lt;BR /&gt;120120 0 0&lt;BR /&gt;130120 0 0&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Apr 2020 12:41:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Episode-identification-with-conditions/m-p/638918#M190012</guid>
      <dc:creator>Bianca1610</dc:creator>
      <dc:date>2020-04-10T12:41:27Z</dc:date>
    </item>
    <item>
      <title>Re: Episode identification with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Episode-identification-with-conditions/m-p/638921#M190013</link>
      <description>&lt;P&gt;It's not clear to me how the logic works, and its also not clear why 090120 is included based on "&lt;SPAN&gt;definition of an episode is that there are 3 days before and after without an Episode (E=0)". Please explain in more detail.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Apr 2020 12:49:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Episode-identification-with-conditions/m-p/638921#M190013</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-04-10T12:49:28Z</dc:date>
    </item>
    <item>
      <title>Re: Episode identification with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Episode-identification-with-conditions/m-p/638922#M190014</link>
      <description>&lt;P&gt;For simplicity I skipped some columns in my dataset. So basically this is part of a symptom diary and I created episodes out of different Symptoms (e.g. runny nose + cough qualifies for a disaese day (E=1), but just runny nose does not qualify for a disease (E=0)). When the Patient was sick a sample was taken (e.g. nasal swab) and now I want to calculate how long he was sick and how severe.&amp;nbsp;So the definition for 1 episode is that there are 3 days before and after without an E=1. After that it will be considered as new infection and does no longer belong to that sample. Like even if the Patient had 1 day whereby the symptoms were not that severe, it doesnt matter because after that there are 2 more days with severe symptoms counting for that episode.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Apr 2020 13:03:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Episode-identification-with-conditions/m-p/638922#M190014</guid>
      <dc:creator>Bianca1610</dc:creator>
      <dc:date>2020-04-10T13:03:02Z</dc:date>
    </item>
    <item>
      <title>Re: Episode identification with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Episode-identification-with-conditions/m-p/638924#M190016</link>
      <description>&lt;P&gt;I still don't see why, given your logic, 090120 is included in the output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's also hard to generalize to code that will work in more than this one situation, but you only give us one situation to work with.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Apr 2020 13:15:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Episode-identification-with-conditions/m-p/638924#M190016</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-04-10T13:15:14Z</dc:date>
    </item>
    <item>
      <title>Re: Episode identification with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Episode-identification-with-conditions/m-p/638934#M190017</link>
      <description>&lt;P&gt;Because after 070120 there are not 3 days with E=0 which will define the end of my episode. As long as there is E=1 and there are not 3 days with E=0 it still belongs to 1 episode&lt;/P&gt;</description>
      <pubDate>Fri, 10 Apr 2020 13:21:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Episode-identification-with-conditions/m-p/638934#M190017</guid>
      <dc:creator>Bianca1610</dc:creator>
      <dc:date>2020-04-10T13:21:29Z</dc:date>
    </item>
    <item>
      <title>Re: Episode identification with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Episode-identification-with-conditions/m-p/638943#M190018</link>
      <description>&lt;P&gt;Here I have code that flags an episode and gives it a number. You could write out the episode number into a second dataset whenever sample is true, and merge that back. Or do that in a SQL step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input date :ddmmyy8. sample episode;
format date yymmddd10.;
datalines;
010120 0 0
020120 0 0
030120 0 0
040120 0 0
050120 1 1
060120 0 1
070120 0 1
080120 0 0
090120 0 1
100120 0 0
110120 0 0
120120 0 0
130120 0 0
;

data want;
merge
  have
  have(firstobs=2 keep=episode rename=(episode=_episode_f_1))
  have(firstobs=3 keep=episode rename=(episode=_episode_f_2))
;
retain _episode_p_1 _episode_p_2 _episode_p_3;
array past {3} _episode_p_1 _episode_p_2 _episode_p_3 (0,0,0);
array future {2} _episode_f_1--_episode_f_2;
retain flag 0 _episode_number 0;
if flag = 0 and sum(of past{*}) = 0 and episode = 1
then do;
  flag = 1;
  _episode_number + 1;
end;
if episode = 0 and sum(of future{*}) = 0 then flag = 0;
if flag then episode_number = _episode_number;
output;
past{mod(_n_,3)+1} = episode;
drop _:;
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Apr 2020 13:34:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Episode-identification-with-conditions/m-p/638943#M190018</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-10T13:34:17Z</dc:date>
    </item>
    <item>
      <title>Re: Episode identification with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Episode-identification-with-conditions/m-p/638947#M190019</link>
      <description>&lt;P&gt;Then why is&amp;nbsp;&lt;SPAN&gt;100120 not requested to be in the output? It seems that it should be in the output given this explanation: "Because after 070120 there are not 3 days with E=0 which will define the end of my episode. As long as there is E=1 and there are not 3 days with E=0 it still belongs to 1 episode". Does the three days with E=0 have to be consecutive days?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Apr 2020 13:36:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Episode-identification-with-conditions/m-p/638947#M190019</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-04-10T13:36:20Z</dc:date>
    </item>
  </channel>
</rss>

