<?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 create multiple time periods using event dates during a specified study period? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-multiple-time-periods-using-event-dates-during-a/m-p/283233#M57706</link>
    <description>&lt;P&gt;This isn't fully tested and I'd be surprised if it worked for all cases, so make sure you test it thoroughly. I think it's also very inefficient but hopefully it gets you started. Perhaps someone can post some more succinct code!&lt;/P&gt;
&lt;P&gt;I renamed time to status, because it made more sense to me logically and was confusing me &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope it helps!&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
informat obs 8. ParticipantID $8. Time Period 8.;
informat mvmtDate mmddyy10.;
format mvmtDate date9.;
input Obs ParticipantID $ Time Period MvmtDate;
cards;
1 00001 0 1 01/31/2007
2 00001 1 2 05/01/2008
3 00002 0 1 06/01/2012
4 00002 1 2 05/24/2013
5 00003 1 1 02/16/2007
6 00003 0 2 05/06/2010
7 00003 1 3 08/19/2010
8 00004 0 1 06/15/2007
9 00004 1 2 06/21/2008
10 00005 0 1 04/27/2007
11 00005 1 2 11/07/2008
12 00006 0 1 03/15/2007
13 00006 1 2 06/20/2007
14 00007 0 1 08/24/2015
15 00008 0 1 04/17/2007
16 00008 1 2 04/19/2007
17 00009 0 1 05/10/2007
18 00009 1 2 08/03/2007
19 00010 0 1 07/31/2007
20 00010 1 2 08/28/2007
21 00010 0 3 02/20/2008
22 00010 1 4 03/05/2008
23 00011 0 1 02/05/2008
24 00011 1 2 03/12/2010
;
run;

data have;
set have;
by participantID;
if first.participantID then do;
	start=mvmtDate;
	time_start=time;
	time=ifn(time_start=1, 0, 1);
	mvmtDate='01Jan2007'd;
	seq=1;
	output;
	seq+1;
	time=time_start;
	mvmtDate=start;
	output;
end;
else do;
	seq+1;
	output;
end;

drop start time_start;
rename time=status;
run;


proc sql;
create table want as 
select h1.ParticipantID, h1.status, h1.period, 
	h1.mvmtDate as date_start format=date9., case when not missing(h2.mvmtDate) then h2.mvmtDate-1 
							else '31Dec2014'd end as date_end format=date9.
from have as h1
left join have as h2
on h1.participantID=h2.ParticipantID
and h1.seq+1=h2.seq
order by h1.participantID, date_start, date_end;
quit;

data want;
set want;
if date_end&amp;gt;'31Dec2014'd then date_end='31Dec2014'd;
if date_start&amp;gt;'31Dec2014'd then delete;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 10 Jul 2016 23:41:23 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-07-10T23:41:23Z</dc:date>
    <item>
      <title>How do I create multiple time periods using event dates during a specified study period?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-multiple-time-periods-using-event-dates-during-a/m-p/283224#M57700</link>
      <description>&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;Hi,&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;I am working in SAS 9.3, doing a study where I look at how subjects move between two different environments (e.g. hospital and home) over time. All dates that correspond to an admission to the hospital are indicated by time=0, and dates that correspond to released from the hospital&amp;nbsp;are indicated by time=1 (so the value of the time variable alternates&amp;nbsp;between 0 and 1 for each row).&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;There is also a variable "period" that represents the order of these events for each subject.&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;If someone moves from the hospital to the home and then back to the hospital, they will&amp;nbsp;have time=0, 1, and then 0 again, and period= 1, 2, then 3.&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;Below is an example of&amp;nbsp;what the data currently looks like:&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;STRONG&gt;&lt;SPAN class="s1"&gt;Obs ParticipantID Time Period MvmtDate&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;1 00001 0 1 01/31/2007&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;2 00001 1 2 05/01/2008&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;3 00002&amp;nbsp;0 1 06/01/2012&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;4 00002 1 2 05/24/2013&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;5 00003 1 1 02/16/2007&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;6 00003 0 2 05/06/2010&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;7 00003 1 3 08/19/2010&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;8 00004 0 1 06/15/2007&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;9 00004 1 2 06/21/2008&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;10 00005 0 1 04/27/2007&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;11 00005 1 2 11/07/2008&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;12 00006 0 1 03/15/2007&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;13 00006 1 2 06/20/2007&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;14 00007 0 1 08/24/2015&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;15 00008 0 1 04/17/2007&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;16 00008 1 2 04/19/2007&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;17 00009 0 1 05/10/2007&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;18 00009 1 2 08/03/2007&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;19 00010 0 1 07/31/2007&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;20&amp;nbsp;00010&amp;nbsp;1 2 08/28/2007&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;21&amp;nbsp;00010&amp;nbsp;0 3 02/20/2008&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;22&amp;nbsp;00010&amp;nbsp;1 4 03/05/2008&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;23 00011 0 1 02/05/2008&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;24 00011 1 2 03/12/2010&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p2"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;My research study period of interest is 01/01/2007 - 12/31/2014.&lt;STRONG&gt; I would like to use the movement dates to create time periods with a start date and end date.&lt;/STRONG&gt;&amp;nbsp;Taking the first subject, for example, with the following data:&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;Time Period&amp;nbsp;MvmtDate&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01/31/2007&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;05/01/2008&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;I would like to transform this subject's data into the following (new/manipulated data/variables are bolded):&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;Time Period&amp;nbsp;&lt;STRONG&gt;PeriodStartDate &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;PeriodEndDate&lt;/STRONG&gt;&amp;nbsp;(MvmtDate - 1 day)&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;&lt;STRONG&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01/01/2007&lt;/STRONG&gt;&amp;nbsp;(study start date) &amp;nbsp; &amp;nbsp;&lt;STRONG&gt;01/30/2007&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01/31/2007 &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;&lt;STRONG&gt;04/30/2008&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;05/01/2008 &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;&lt;STRONG&gt;12/31/2014&lt;/STRONG&gt;&amp;nbsp;(study end date, in this case date of censoring)&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;Do you have any suggestions? I started off by making a separate database to create the first time period (starting 01/01/2007) which I planned to merge in. Then I thought I could create two separate databases to get start and end dates (e.g. 01/31/2007 and 04/30/2008) and merge together into the appropriate rows by offsetting the period variable. But then I realized&amp;nbsp;that creating the last time period (ending with 12/31/2014) might&amp;nbsp;be difficult, and my code is starting to get very complicated. Perhaps there is a way to do this using PROC SQL? Any suggestions would be&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="s2"&gt;greatly&lt;/SPAN&gt;&lt;SPAN class="s1"&gt;&amp;nbsp;appreciated. Thank you!&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p2"&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Jul 2016 20:55:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-multiple-time-periods-using-event-dates-during-a/m-p/283224#M57700</guid>
      <dc:creator>Kels123</dc:creator>
      <dc:date>2016-07-10T20:55:45Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create multiple time periods using event dates during a specified study period?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-multiple-time-periods-using-event-dates-during-a/m-p/283233#M57706</link>
      <description>&lt;P&gt;This isn't fully tested and I'd be surprised if it worked for all cases, so make sure you test it thoroughly. I think it's also very inefficient but hopefully it gets you started. Perhaps someone can post some more succinct code!&lt;/P&gt;
&lt;P&gt;I renamed time to status, because it made more sense to me logically and was confusing me &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope it helps!&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
informat obs 8. ParticipantID $8. Time Period 8.;
informat mvmtDate mmddyy10.;
format mvmtDate date9.;
input Obs ParticipantID $ Time Period MvmtDate;
cards;
1 00001 0 1 01/31/2007
2 00001 1 2 05/01/2008
3 00002 0 1 06/01/2012
4 00002 1 2 05/24/2013
5 00003 1 1 02/16/2007
6 00003 0 2 05/06/2010
7 00003 1 3 08/19/2010
8 00004 0 1 06/15/2007
9 00004 1 2 06/21/2008
10 00005 0 1 04/27/2007
11 00005 1 2 11/07/2008
12 00006 0 1 03/15/2007
13 00006 1 2 06/20/2007
14 00007 0 1 08/24/2015
15 00008 0 1 04/17/2007
16 00008 1 2 04/19/2007
17 00009 0 1 05/10/2007
18 00009 1 2 08/03/2007
19 00010 0 1 07/31/2007
20 00010 1 2 08/28/2007
21 00010 0 3 02/20/2008
22 00010 1 4 03/05/2008
23 00011 0 1 02/05/2008
24 00011 1 2 03/12/2010
;
run;

data have;
set have;
by participantID;
if first.participantID then do;
	start=mvmtDate;
	time_start=time;
	time=ifn(time_start=1, 0, 1);
	mvmtDate='01Jan2007'd;
	seq=1;
	output;
	seq+1;
	time=time_start;
	mvmtDate=start;
	output;
end;
else do;
	seq+1;
	output;
end;

drop start time_start;
rename time=status;
run;


proc sql;
create table want as 
select h1.ParticipantID, h1.status, h1.period, 
	h1.mvmtDate as date_start format=date9., case when not missing(h2.mvmtDate) then h2.mvmtDate-1 
							else '31Dec2014'd end as date_end format=date9.
from have as h1
left join have as h2
on h1.participantID=h2.ParticipantID
and h1.seq+1=h2.seq
order by h1.participantID, date_start, date_end;
quit;

data want;
set want;
if date_end&amp;gt;'31Dec2014'd then date_end='31Dec2014'd;
if date_start&amp;gt;'31Dec2014'd then delete;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Jul 2016 23:41:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-multiple-time-periods-using-event-dates-during-a/m-p/283233#M57706</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-07-10T23:41:23Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create multiple time periods using event dates during a specified study period?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-multiple-time-periods-using-event-dates-during-a/m-p/283242#M57715</link>
      <description>&lt;P&gt;I love this question . You need to test it on your own. I may not consider about all the scenarios .&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 have;
informat obs 8. ParticipantID $8. Time Period 8.;
informat mvmtDate mmddyy10.;
format mvmtDate date9.;
input Obs ParticipantID $ Time Period MvmtDate;
cards;
1 00001 0 1 01/31/2007
2 00001 1 2 05/01/2008
3 00002 0 1 06/01/2012
4 00002 1 2 05/24/2013
5 00003 1 1 02/16/2007
6 00003 0 2 05/06/2010
7 00003 1 3 08/19/2010
8 00004 0 1 06/15/2007
9 00004 1 2 06/21/2008
10 00005 0 1 04/27/2007
11 00005 1 2 11/07/2008
12 00006 0 1 03/15/2007
13 00006 1 2 06/20/2007
14 00007 0 1 08/24/2015
15 00008 0 1 04/17/2007
16 00008 1 2 04/19/2007
17 00009 0 1 05/10/2007
18 00009 1 2 08/03/2007
19 00010 0 1 07/31/2007
20 00010 1 2 08/28/2007
21 00010 0 3 02/20/2008
22 00010 1 4 03/05/2008
23 00011 0 1 02/05/2008
24 00011 1 2 03/12/2010
;
run;

data want;
array t{99999} _temporary_;
array p{99999} _temporary_;
array d{99999} _temporary_;

do i=1 by 1 until(last.ParticipantID);
 set have(where=(MvmtDate between '01jan2007'd and '31dec2014'd));
 by ParticipantID ;
 t{i}=Time ;
 p{i}=Period ;
 d{i}=MvmtDate ;
end;
 
 
do j=1 to i;

 if j=1 then do; 
  if d{1} gt '01jan2007'd then do;
   Time=not t{1};
   Period=p{1}-1;
   PeriodStartDate='01jan2007'd;
   PeriodEndDate=d{1}-1;
   output;
   Time=t{1};
   Period=p{1};
   PeriodStartDate=d{1};
   PeriodEndDate=d{2}-1;
   output;
  end;
  else do;
   Time=t{1};
   Period=p{1};
   PeriodStartDate='01jan2007'd;
   PeriodEndDate=d{2}-1;
   output;
  end;  
 end; 
 
 else if j=i then do;
   Time=t{j};
   Period=p{j};
   PeriodStartDate=d{j};
   PeriodEndDate='31dec2014'd;
   output;
 end;
 
 else do;
   Time=t{j};
   Period=p{j};
   PeriodStartDate=d{j};
   PeriodEndDate=d{j+1}-1;
   output;
 end;
 
end;

format PeriodStartDate PeriodEndDate date9.;
keep ParticipantID  Time Period PeriodStartDate PeriodEndDate;
run;
 &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Jul 2016 01:58:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-multiple-time-periods-using-event-dates-during-a/m-p/283242#M57715</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-07-11T01:58:20Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create multiple time periods using event dates during a specified study period?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-multiple-time-periods-using-event-dates-during-a/m-p/283244#M57716</link>
      <description>&lt;P&gt;This is my take on this problem, run it to see if you like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
length PID $5;
input Obs PID release period date :mmddyy10.;
format date yymmdd10.;
drop obs period;
datalines;
1 00001 0 1 01/31/2007
2 00001 1 2 05/01/2008
3 00002 0 1 06/01/2012
4 00002 1 2 05/24/2013
5 00003 1 1 02/16/2007
6 00003 0 2 05/06/2010
7 00003 1 3 08/19/2010
8 00004 0 1 06/15/2007
9 00004 1 2 06/21/2008
10 00005 0 1 04/27/2007
11 00005 1 2 11/07/2008
12 00006 0 1 03/15/2007
13 00006 1 2 06/20/2007
14 00007 0 1 08/24/2015
15 00008 0 1 04/17/2007
16 00008 1 2 04/19/2007
17 00009 0 1 05/10/2007
18 00009 1 2 08/03/2007
19 00010 0 1 07/31/2007
20 00010 1 2 08/28/2007
21 00010 0 3 02/20/2008
22 00010 1 4 03/05/2008
23 00011 0 1 02/05/2008
24 00011 1 2 03/12/2010
;

%let studyStart='01JAN2007'd;
%let studyEnd='31DEC2014'd;

data want;
length environment $8;
format startDate endDate yymmdd10.;
period = 0;
endDate = intnx("DAY", &amp;amp;studyStart, -1);
do until (last.PID);
    set have; by PID date; /* Also check date order */
    where date &amp;gt; &amp;amp;studyStart and date &amp;lt; &amp;amp;studyEnd;
    if release 
        then environment = "HOSPITAL";
        else environment = "HOME";
    startDate = intnx("DAY", endDate, 1);
    endDate = intnx("DAY", date, -1);
    period + 1;
    output;
    if last.PID then do;
        startDate = intnx("DAY", endDate, 1);
        endDate = &amp;amp;studyEnd;
        if release 
            then environment = "HOME";
            else environment = "HOSPITAL";
        period + 1;
        output;
        end;
    end;
keep PID period environment startDate endDate;
run;

proc print data=want;
var period environment startDate endDate;
by PID; id PID;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Jul 2016 04:16:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-multiple-time-periods-using-event-dates-during-a/m-p/283244#M57716</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-07-11T04:16:57Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create multiple time periods using event dates during a specified study period?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-multiple-time-periods-using-event-dates-during-a/m-p/283479#M57746</link>
      <description>&lt;P&gt;I'm still checking the results, but so far it looks like this works perfectly! Thank you so so very much!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jul 2016 13:53:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-multiple-time-periods-using-event-dates-during-a/m-p/283479#M57746</guid>
      <dc:creator>Kels123</dc:creator>
      <dc:date>2016-07-11T13:53:07Z</dc:date>
    </item>
  </channel>
</rss>

