<?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: How do i find days betten first and second and second and third episode date on a single cliernt in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-find-days-betten-first-and-second-and-second-and-third/m-p/724290#M224863</link>
    <description>&lt;P&gt;Change one line:&lt;/P&gt;
&lt;P&gt;instead&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; max(Episodedate) - min(Episodedate) as repeat_inf_day&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;try:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;(calculated episode2 - calculated episode1) as repeat_inf_day&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 07 Mar 2021 18:55:39 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2021-03-07T18:55:39Z</dc:date>
    <item>
      <title>How do i find days betten first and second and second and third episode date on a single cliernt?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-find-days-betten-first-and-second-and-second-and-third/m-p/724288#M224862</link>
      <description>&lt;P&gt;Hi I have a data like this&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; Test;&lt;/P&gt;
&lt;P&gt;input ClientID IncidentID Episodedate&amp;nbsp;mmddyy10.;&lt;/P&gt;
&lt;P&gt;cards;&lt;/P&gt;
&lt;P&gt;4750 3119 03/05/2018&lt;/P&gt;
&lt;P&gt;1021 3110 11/06/2018&lt;/P&gt;
&lt;P&gt;1021 3111 01/07/2019&lt;/P&gt;
&lt;P&gt;4765&amp;nbsp;3576 03/28/2019&lt;/P&gt;
&lt;P&gt;4767 3821 10/25/2019&lt;/P&gt;
&lt;P&gt;4770 3332 10/08/2018&lt;/P&gt;
&lt;P&gt;4770 3631 05/23/2019&lt;/P&gt;
&lt;P&gt;4770 3798 10/09/2019&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want&lt;/P&gt;
&lt;P&gt;ClientID IncidentID Episode Date Days between first and second Episode Days between second and third Episode&lt;/P&gt;
&lt;P&gt;4750 3119 03/05/2018&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;1021 3110 11/06/2018&lt;/P&gt;
&lt;P&gt;1021 3111 01/07/2019&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;52&lt;/P&gt;
&lt;P&gt;4765&amp;nbsp;3576 03/28/2019&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;0&lt;/P&gt;
&lt;P&gt;4767 3821 10/25/2019&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;0&lt;/P&gt;
&lt;P&gt;4770 3332 10/08/2018&lt;/P&gt;
&lt;P&gt;4770 3631 05/23/2019&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 227&lt;/P&gt;
&lt;P&gt;4770 3798 10/09/2019&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;180&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please help me.&amp;nbsp; It needs to be grouped by client id.&amp;nbsp; Some client id has more than three episodes in two year period.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried this, did not work.&lt;/P&gt;
&lt;PRE&gt;proc sql;
create table repeat as
select
      clientid,
     min(Episodedate) as Episode1,
     max(Episodedate) as Episode2,
	 max(Episodedate) - min(Episodedate) as repeat_inf_day
from
have
group by  Clientid;
quit;&lt;/PRE&gt;</description>
      <pubDate>Sun, 07 Mar 2021 18:25:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-find-days-betten-first-and-second-and-second-and-third/m-p/724288#M224862</guid>
      <dc:creator>Dhana18</dc:creator>
      <dc:date>2021-03-07T18:25:00Z</dc:date>
    </item>
    <item>
      <title>Re: How do i find days betten first and second and second and third episode date on a single cliernt</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-find-days-betten-first-and-second-and-second-and-third/m-p/724290#M224863</link>
      <description>&lt;P&gt;Change one line:&lt;/P&gt;
&lt;P&gt;instead&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; max(Episodedate) - min(Episodedate) as repeat_inf_day&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;try:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;(calculated episode2 - calculated episode1) as repeat_inf_day&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Mar 2021 18:55:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-find-days-betten-first-and-second-and-second-and-third/m-p/724290#M224863</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-03-07T18:55:39Z</dc:date>
    </item>
    <item>
      <title>Re: How do i find days between first and second and second and third episode date on a single client</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-find-days-betten-first-and-second-and-second-and-third/m-p/724293#M224864</link>
      <description>Thank you for your response. I greatly appreciate it.  It gave me days between first and second episode, but there are clients with more than two episode dates three or sometimes four episode date in two year period. How do I modify the code to get days difference between second and third episode and third and fourth?  Please!!&lt;BR /&gt;&lt;BR /&gt;I tried this but did not work.&lt;BR /&gt;proc sql;&lt;BR /&gt;create table repeat as&lt;BR /&gt;select&lt;BR /&gt;     clientid,&lt;BR /&gt;     min(Episodedate) as Episode1,&lt;BR /&gt;     max(Episodedate) as Episode2,&lt;BR /&gt;      min(Episodedate) as Episode3,&lt;BR /&gt;     max(Episodedate) as Episode4,&lt;BR /&gt;      (calculated episode2 - calculated episode1) as repeat_inf_day1&lt;BR /&gt;      (calculated episode3 - calculated episode2) as repeat_inf_day1&lt;BR /&gt;      (calculated episode4 - calculated episode3) as repeat_inf_day3&lt;BR /&gt;from New_1&lt;BR /&gt;group by  Clientid;&lt;BR /&gt;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sun, 07 Mar 2021 19:09:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-find-days-betten-first-and-second-and-second-and-third/m-p/724293#M224864</guid>
      <dc:creator>Dhana18</dc:creator>
      <dc:date>2021-03-07T19:09:45Z</dc:date>
    </item>
    <item>
      <title>Re: How do i find days between first and second and second and third episode date on a single client</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-find-days-betten-first-and-second-and-second-and-third/m-p/724297#M224865</link>
      <description>&lt;P&gt;As much as I know:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &lt;STRONG&gt;min&lt;/STRONG&gt;(episodate) with group by clientID will result in &lt;STRONG&gt;first&lt;/STRONG&gt; &lt;STRONG&gt;episod&lt;/STRONG&gt; date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;STRONG&gt;max&lt;/STRONG&gt;(episodate) with group by clientID will result in &lt;STRONG&gt;latest&lt;/STRONG&gt; &lt;STRONG&gt;episod&lt;/STRONG&gt; date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is no Eisod3, Episod4 ... etc. - no matter how many episodes has a client.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Mar 2021 19:33:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-find-days-betten-first-and-second-and-second-and-third/m-p/724297#M224865</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-03-07T19:33:54Z</dc:date>
    </item>
    <item>
      <title>Re: How do i find days between first and second and second and third episode date on a single client</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-find-days-betten-first-and-second-and-second-and-third/m-p/724304#M224869</link>
      <description>&lt;P&gt;One Way :&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;data Test;
format Episodedate mmddyy10.;
input ClientID IncidentID Episodedate mmddyy10.;
cards;
4750 3119 03/05/2018
1021 3110 11/06/2018
1021 3111 01/07/2019
4765 3576 03/28/2019
4767 3821 10/25/2019
4770 3332 10/08/2018
4770 3631 05/23/2019
4770 3798 10/09/2019
run;

data want;
	array edt[99] _temporary_;

	do i=1 by 1 until(last.ClientID);
		set Test;
		by ClientID notsorted;
		edt[i]=Episodedate;
	end;

	do j=1 by 1 until(last.ClientID);
		set Test;
		by ClientID notsorted;		
		if j = 2 then 	repeat_inf_day=Episodedate-edt[j-1];
		if j = 3 then 	repeat_inf_day2=Episodedate-edt[j-1];
		if j = 4 then 	repeat_inf_day3=Episodedate-edt[j-1];
		output;
		call missing(of repeat_inf_day:);
	end;
	
	drop i j;
	
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;bs	Episodedate	ClientID	IncidentID	repeat_inf_day	repeat_inf_day2	repeat_inf_day3
1	03/05/2018	4750	3119	.	.	.
2	11/06/2018	1021	3110	.	.	.
3	01/07/2019	1021	3111	62	.	.
4	03/28/2019	4765	3576	.	.	.
5	10/25/2019	4767	3821	.	.	.
6	10/08/2018	4770	3332	.	.	.
7	05/23/2019	4770	3631	227	.	.
8	10/09/2019	4770	3798	.	139	.&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Mar 2021 20:28:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-find-days-betten-first-and-second-and-second-and-third/m-p/724304#M224869</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2021-03-07T20:28:44Z</dc:date>
    </item>
    <item>
      <title>Re: How do i find days betten first and second and second and third episode date on a single cliernt</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-find-days-betten-first-and-second-and-second-and-third/m-p/724465#M224930</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Test;
format Episodedate mmddyy10.;
input ClientID IncidentID Episodedate mmddyy10.;
format Episodedate mmddyy10.;
cards;
4750 3119 03/05/2018
1021 3110 11/06/2018
1021 3111 01/07/2019
4765 3576 03/28/2019
4767 3821 10/25/2019
4770 3332 10/08/2018
4770 3631 05/23/2019
4770 3798 10/09/2019
;
run;

data want;
 set test;
 by ClientID notsorted;
 x=dif(Episodedate);
 if first.ClientID then do;n=0;call missing(x);end;
 n+1;
 if n=2 then repeat_inf_day2=x;
  else if n=3 then repeat_inf_day3=x;
drop x n;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Mar 2021 11:34:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-find-days-betten-first-and-second-and-second-and-third/m-p/724465#M224930</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-03-08T11:34:36Z</dc:date>
    </item>
    <item>
      <title>Re: How do i find days betten first and second and second and third episode date on a single cliernt</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-find-days-betten-first-and-second-and-second-and-third/m-p/724506#M224939</link>
      <description>&lt;P&gt;Thank you so much you made my day!!!&lt;/P&gt;</description>
      <pubDate>Mon, 08 Mar 2021 14:27:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-find-days-betten-first-and-second-and-second-and-third/m-p/724506#M224939</guid>
      <dc:creator>Dhana18</dc:creator>
      <dc:date>2021-03-08T14:27:26Z</dc:date>
    </item>
  </channel>
</rss>

