<?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: Create groups by amount of time between patient visits in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-groups-by-amount-of-time-between-patient-visits/m-p/816271#M322167</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PtID TestLevel TestDt          Episode  Total
1     10        01/01/1990      1        3
1     22        01/02/1990      1        3
1     30        01/22/1990      2        3
1     25        09/01/1992      3        3
1     35        09/08/1992      3        3 
2     54        01/10/1995      4        3
2     54        01/11/1995      4        3 
2     54        01/12/1995      4        3
2     87        12/01/1998      5        3
2     66        12/22/1998      6        3&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;Thank you, Reeza. One more question about the first part of coding for the 'Episode'. How would it change to get episode numbers like this? Eg-&amp;nbsp;The&amp;nbsp;episode&amp;nbsp;numbers&amp;nbsp;are&amp;nbsp;consecutive.&lt;/CODE&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 02 Jun 2022 22:56:52 GMT</pubDate>
    <dc:creator>Abishekaa</dc:creator>
    <dc:date>2022-06-02T22:56:52Z</dc:date>
    <item>
      <title>Create groups by amount of time between patient visits</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-groups-by-amount-of-time-between-patient-visits/m-p/816254#M322153</link>
      <description>&lt;P&gt;Hi all, thanks in advance for your advice on this. This is my sample dataset. The variables I WANT to create are 'Episode' and 'Total'&lt;/P&gt;
&lt;P&gt;Episode - (Pt 1) - All test dates within 10 days are considered to be one Episode. Therefore, the first two observations are one episode, the third observation is one episode, and the fourth and fifth observations are one episode.&lt;/P&gt;
&lt;P&gt;Total - Total episodes for each patient - Patient 1 has 3 episodes total, and patient 2 has 3 episodes total.&lt;/P&gt;
&lt;P&gt;Please advise on how to create the 'Episode' variable by grouping test dates within a 10 day period?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PtID TestLevel TestDt          Episode  Total
1     10        01/01/1990      1        3
1     22        01/02/1990      1        3
1     30        01/22/1990      2        3
1     25        09/01/1992      3        3
1     35        09/08/1992      3        3 
2     54        01/10/1995      1        3
2     54        01/11/1995      1        3 
2     54        01/12/1995      1        3
2     87        12/01/1998      2        3
2     66        12/22/1998      3        3
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jun 2022 20:20:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-groups-by-amount-of-time-between-patient-visits/m-p/816254#M322153</guid>
      <dc:creator>Abishekaa</dc:creator>
      <dc:date>2022-06-02T20:20:53Z</dc:date>
    </item>
    <item>
      <title>Re: Create groups by amount of time between patient visits</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-groups-by-amount-of-time-between-patient-visits/m-p/816255#M322154</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	infile cards;
	input PtID TestLevel TestDt  : mmddyy10.        Episode Total;
	cards;
1     10        01/01/1990      1        3
1     22        01/02/1990      1        3
1     30        01/22/1990      2        3
1     25        09/01/1992      3        3
1     35        09/08/1992      3        3 
2     54        01/10/1995      1        3
2     54        01/11/1995      1        3 
2     54        01/12/1995      1        3
2     87        12/01/1998      2        3
2     66        12/22/1998      3        3
;
	;
	;;
run;

data part1;
	set have;
	by ptID;
	retain index_date episode_counter;

	if first.ptid then
		do;
			index_date=testdt;
			episode_counter=1;
		end;

	if testdt - index_date &amp;gt; 10 then
		do;
			episode_counter + 1;
			index_date=testdt;
		end;
run;

proc sql;
	create table want as select *, max(episode) as check_total from part1 group by 
		ptid order by 1, 3;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Jun 2022 20:34:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-groups-by-amount-of-time-between-patient-visits/m-p/816255#M322154</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-06-02T20:34:23Z</dc:date>
    </item>
    <item>
      <title>Re: Create groups by amount of time between patient visits</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-groups-by-amount-of-time-between-patient-visits/m-p/816259#M322157</link>
      <description>&lt;P&gt;Just for your consideration: what if the dates are all exactly 3 days apart and there are 20 dates for the same Id? The third date would be 9 days from the first so in the 10 days for that as an episode. Now the fourth date is 3 days from the last of the first episode but more than 10 from the first date of episode 1. So is that a new episode or not?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So where are the episode breaks in:&lt;/P&gt;
&lt;PRE&gt;5 07/01/2022
5 07/04/2022
5 07/07/2022
5 07/10/2022
5 07/13/2022
5 07/16/2022
5 07/19/2022
5 07/22/2022
5 07/25/2022
5 07/28/2022
5 07/31/2022
5 08/03/2022
5 08/06/2022
5 08/09/2022
5 08/12/2022
5 08/15/2022
5 08/18/2022
5 08/21/2022
5 08/24/2022
5 08/27/2022
5 08/30/2022
&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Jun 2022 20:55:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-groups-by-amount-of-time-between-patient-visits/m-p/816259#M322157</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-06-02T20:55:37Z</dc:date>
    </item>
    <item>
      <title>Re: Create groups by amount of time between patient visits</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-groups-by-amount-of-time-between-patient-visits/m-p/816269#M322165</link>
      <description>Hi Reeza, thanks so much for the answer! Could you please explain how the sql step works? Specially the 'part1' and 'ptid order by 1,3' ?</description>
      <pubDate>Thu, 02 Jun 2022 22:39:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-groups-by-amount-of-time-between-patient-visits/m-p/816269#M322165</guid>
      <dc:creator>Abishekaa</dc:creator>
      <dc:date>2022-06-02T22:39:35Z</dc:date>
    </item>
    <item>
      <title>Re: Create groups by amount of time between patient visits</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-groups-by-amount-of-time-between-patient-visits/m-p/816270#M322166</link>
      <description>Group by 1, 3 is short hand notation to sort by columns 1/3.&lt;BR /&gt;&lt;BR /&gt;Part1 is the data set from the previous step. &lt;BR /&gt;&lt;BR /&gt;All it's doing is getting the maximum per group and adding it in. However, SQL doesn't maintain default order so I sort to ensure you get the same order back.&lt;BR /&gt;There are multiple ways to accomplish this step, with SQL being the easiest. &lt;BR /&gt;&lt;BR /&gt;This post covers the average, but in your case it's the maximum. &lt;BR /&gt;&lt;A href="https://github.com/statgeek/SAS-Tutorials/blob/master/add_average_value_to_dataset.sas" target="_blank"&gt;https://github.com/statgeek/SAS-Tutorials/blob/master/add_average_value_to_dataset.sas&lt;/A&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 02 Jun 2022 22:41:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-groups-by-amount-of-time-between-patient-visits/m-p/816270#M322166</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-06-02T22:41:47Z</dc:date>
    </item>
    <item>
      <title>Re: Create groups by amount of time between patient visits</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-groups-by-amount-of-time-between-patient-visits/m-p/816271#M322167</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PtID TestLevel TestDt          Episode  Total
1     10        01/01/1990      1        3
1     22        01/02/1990      1        3
1     30        01/22/1990      2        3
1     25        09/01/1992      3        3
1     35        09/08/1992      3        3 
2     54        01/10/1995      4        3
2     54        01/11/1995      4        3 
2     54        01/12/1995      4        3
2     87        12/01/1998      5        3
2     66        12/22/1998      6        3&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;Thank you, Reeza. One more question about the first part of coding for the 'Episode'. How would it change to get episode numbers like this? Eg-&amp;nbsp;The&amp;nbsp;episode&amp;nbsp;numbers&amp;nbsp;are&amp;nbsp;consecutive.&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jun 2022 22:56:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-groups-by-amount-of-time-between-patient-visits/m-p/816271#M322167</guid>
      <dc:creator>Abishekaa</dc:creator>
      <dc:date>2022-06-02T22:56:52Z</dc:date>
    </item>
    <item>
      <title>Re: Create groups by amount of time between patient visits</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-groups-by-amount-of-time-between-patient-visits/m-p/816274#M322168</link>
      <description>&lt;P&gt;Change this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	if first.ptid then
		do;
			index_date=testdt;
			episode_counter=1;
		end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
	
      if first.ptid then
		do;
			index_date=testdt;
			episode_counter+1;
		end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You may need to set the episode_counter to 0 on the retain statement as well:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;retain episode_counter 0;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Jun 2022 23:24:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-groups-by-amount-of-time-between-patient-visits/m-p/816274#M322168</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-06-02T23:24:28Z</dc:date>
    </item>
  </channel>
</rss>

