<?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: calculating person-time in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/calculating-person-time/m-p/264606#M57800</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A few questions. &amp;nbsp;Why is date character, its far easier to use numeric dates. &amp;nbsp;Also, where&lt;SPAN&gt;CC&amp;nbsp;start_date=01/04/2015 and end_date=01/05/2015 *date of last enrollment;&lt;/SPAN&gt;r does this record come from:&lt;/P&gt;
&lt;P&gt;I can't see why 01/05 is calculated as its not in the test data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use simple if statements to get it:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  end_date=start_date;
  stop=1;
  if day1 ne . then end_date=end_date+1; else stop=0;
  if day2 ne . and stop then end_date=end_date+1;
  if day3 ne . and stop then end_date=end_date+1;
...
run;&lt;/PRE&gt;</description>
    <pubDate>Mon, 18 Apr 2016 15:30:03 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2016-04-18T15:30:03Z</dc:date>
    <item>
      <title>calculating person-time</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/calculating-person-time/m-p/264586#M57786</link>
      <description>&lt;P&gt;Hi SAS community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm doing a survival analysis where I need to calculate person-time. For my dataset, I don't have a variables with specific&amp;nbsp;end dates, rather I have days of enrollment.&amp;nbsp; I would like to calculate the person-time for each individual.&amp;nbsp; Can you help with a code that calculates an end date based on time to event, loss-to-follow-up or end of study - which ever comes first? Below is a simple dataset that represents my data. Day1 is the start date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;input ID $ Start_Date $ Day1 Day2 Day3 Day4 Day5 Event_date;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;AA 01/01/2015 1 1 1 1 1 01/04/2015&lt;/P&gt;&lt;P&gt;BB 02/01/2015 1&amp;nbsp;. 1 1 1&amp;nbsp; 02/20/2015&lt;/P&gt;&lt;P&gt;CC 01/04/2015 1 1 . . . .&lt;/P&gt;&lt;P&gt;DD 02/10/2015&amp;nbsp;1 1 1 . 1 02/15/2015&lt;/P&gt;&lt;P&gt;EE 02/07/2015 1 1 1 1 1 .&lt;/P&gt;&lt;P&gt;FF 01/30/2015 1 1 1 1 1 01/31/2015&lt;/P&gt;&lt;P&gt;;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;AA start_date=01/01/2015 and end_date=01/04/2015 *date of event&lt;/P&gt;&lt;P&gt;BB start_date=02/01/2015 and end_date=02/01/2015 *date of last enrollment;&lt;/P&gt;&lt;P&gt;CC&amp;nbsp;start_date=01/04/2015 and end_date=01/05/2015 *date of last enrollment;&lt;/P&gt;&lt;P&gt;DD&amp;nbsp;start_date=02/10/2015 and end_date=02/12/2015 *date of last enrollment&lt;/P&gt;&lt;P&gt;EE&amp;nbsp;start_date=02/07/2015 and end_date=02/11/2015&amp;nbsp; *date of last enrollment&lt;/P&gt;&lt;P&gt;FF start_date=01/30/2015 and end_date=01/31/2015 *date of event;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Apr 2016 14:53:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/calculating-person-time/m-p/264586#M57786</guid>
      <dc:creator>sophia_SAS</dc:creator>
      <dc:date>2016-04-18T14:53:49Z</dc:date>
    </item>
    <item>
      <title>Re: calculating person-time</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/calculating-person-time/m-p/264606#M57800</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A few questions. &amp;nbsp;Why is date character, its far easier to use numeric dates. &amp;nbsp;Also, where&lt;SPAN&gt;CC&amp;nbsp;start_date=01/04/2015 and end_date=01/05/2015 *date of last enrollment;&lt;/SPAN&gt;r does this record come from:&lt;/P&gt;
&lt;P&gt;I can't see why 01/05 is calculated as its not in the test data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use simple if statements to get it:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  end_date=start_date;
  stop=1;
  if day1 ne . then end_date=end_date+1; else stop=0;
  if day2 ne . and stop then end_date=end_date+1;
  if day3 ne . and stop then end_date=end_date+1;
...
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 Apr 2016 15:30:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/calculating-person-time/m-p/264606#M57800</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-04-18T15:30:03Z</dc:date>
    </item>
    <item>
      <title>Re: calculating person-time</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/calculating-person-time/m-p/264629#M57801</link>
      <description>&lt;P&gt;Hi RW9,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your reply and suggested code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The variable end_date does not exist in my original dataset. I need to create that variable based on the variables that exist (i.e. start_date, day1-day5, event_date). In the space after the sample dataset, I was giving examples of what the end_date value should be for these instances.&amp;nbsp; Regarding your question about CC. The end_date =&amp;nbsp;01/05/2015 because CC was enrolled for two days, starting on 01/04/2015.&amp;nbsp; The ideal code should create the end_date variable with 01/05/2015 as the value for subject ID&amp;nbsp;CC.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 18 Apr 2016 17:29:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/calculating-person-time/m-p/264629#M57801</guid>
      <dc:creator>sophia_SAS</dc:creator>
      <dc:date>2016-04-18T17:29:14Z</dc:date>
    </item>
    <item>
      <title>Re: calculating person-time</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/calculating-person-time/m-p/264656#M57804</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/9463"&gt;@sophia_SAS﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;array day day:;&lt;BR /&gt;do m=1 to dim(day) while(day[m]);&lt;BR /&gt;end;&lt;BR /&gt;if m &amp;gt;= 2 then end_date=min(start_date+m-2, event_date);&lt;BR /&gt;else put 'WAR' 'NING: For ' id= 'Day1 is missing! End_date has been set to missing.';&lt;BR /&gt;format end_date mmddyy10.;&lt;BR /&gt;keep id start_date end_date;&lt;BR /&gt;run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 Apr 2016 19:36:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/calculating-person-time/m-p/264656#M57804</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-04-18T19:36:03Z</dc:date>
    </item>
    <item>
      <title>Re: calculating person-time</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/calculating-person-time/m-p/264661#M57805</link>
      <description>&lt;P&gt;Hi Freelance Reinhard!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your code worked beautifully.&amp;nbsp; Thank you for putting it together.&amp;nbsp; However, when I went to apply it&amp;nbsp;to my actual dataset, it wasn't working.&amp;nbsp; It was here that I realized the set-up I had in my sample 'have' dataset is different than my actual one.&amp;nbsp; Apologies for wasting your time.&amp;nbsp; My actual dataset has continuous days starting from the beginning of the entire dataset vs starting from the enrollees start date.&amp;nbsp; (i.e. day1 always equals 01/01/2015, regardless of the enrollee's start date) So using my same sample dataset, here's a revised sample dataset. I've revised some of the dates, but rules still apply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;input ID $ Start_Date $ Day1 Day2 Day3 Day4 Day5 Event_date;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;AA 01/01/2015 1 1 1 1 1 01/04/2015&lt;/P&gt;&lt;P&gt;BB 01/03/2015&amp;nbsp;.&amp;nbsp;. 1 1 1&amp;nbsp; .&lt;/P&gt;&lt;P&gt;CC 01/04/2015&amp;nbsp;. . .&amp;nbsp;1 . .&lt;/P&gt;&lt;P&gt;DD 01/01/2015&amp;nbsp;1 1 1 . 1 02/15/2015&lt;/P&gt;&lt;P&gt;EE 01/01/2015 1 1 1 1 1 .&lt;/P&gt;&lt;P&gt;FF 01/02/2015&amp;nbsp;. 1 1 1 1 01/03/2015&lt;/P&gt;&lt;P&gt;;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;AA start_date=01/01/2015 and end_date=01/04/2015 *date of event&lt;/P&gt;&lt;P&gt;BB start_date=01/03/2015 and end_date=01/05/2015 *date of last enrollment;&lt;/P&gt;&lt;P&gt;CC&amp;nbsp;start_date=01/04/2015 and end_date=01/04/2015 *date of last enrollment;&lt;/P&gt;&lt;P&gt;DD&amp;nbsp;start_date=01/01/2015 and end_date=01/03/2015 *date of last enrollment&lt;/P&gt;&lt;P&gt;EE&amp;nbsp;start_date=01/01/2015 and end_date=01/01/2015&amp;nbsp; *date of last enrollment&lt;/P&gt;&lt;P&gt;FF start_date=01/02/2015 and end_date=01/02/2015 *date of event;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Apr 2016 20:14:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/calculating-person-time/m-p/264661#M57805</guid>
      <dc:creator>sophia_SAS</dc:creator>
      <dc:date>2016-04-18T20:14:10Z</dc:date>
    </item>
    <item>
      <title>Re: calculating person-time</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/calculating-person-time/m-p/264675#M57808</link>
      <description>&lt;P&gt;No problem. Please find below an adapted version of my code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
retain studystart '01JAN2015'd;
set have;
array day day:;
do m=start_date-studystart+1 to dim(day) while(day[m]);
end;
if m &amp;gt;= start_date-studystart+2 then end_date=min(studystart+m-2, event_date);
else put 'WAR' 'NING: DayX for start date of ' id= 'is missing! End_date has been set to missing.';
format end_date mmddyy10.;
keep id start_date end_date;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Please note (I forgot to mention this in my earlier post) that I use a numeric (SAS date) variable START_DATE, not a character variable as is suggested by your data step. Is START_DATE in your real data a character variable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As in my&amp;nbsp;earlier code, I let SAS write a warning to the log and set END_DATE to missing if the DAY&lt;EM&gt;x&lt;/EM&gt; variable corresponding to a patient's start date is missing and not 1 as in your sample data. (Or should these cases, if any, be handled differently?)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Finally, I noticed two inconsistencies in your new sample output:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Patient EE should have end_date=01/&lt;STRONG&gt;05&lt;/STRONG&gt;/2015.*&lt;/LI&gt;
&lt;LI&gt;P&lt;SPAN&gt;atient FF should have end_date=01/&lt;/SPAN&gt;&lt;STRONG&gt;03&lt;/STRONG&gt;&lt;SPAN&gt;/2015 (the date of event).*&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&lt;SPAN&gt;* if I understand the logic correctly&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Apr 2016 21:05:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/calculating-person-time/m-p/264675#M57808</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-04-18T21:05:35Z</dc:date>
    </item>
    <item>
      <title>Re: calculating person-time</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/calculating-person-time/m-p/264732#M57811</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sorry, did you actually try my code? &amp;nbsp;end_date is created in my datastep per below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the second point, why would CC have 01/05 - this is not 2 days after 01/04? &amp;nbsp;Am am not seeing the logic of how you go:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;start_date=01/04/2015 - then nothing in day 1-3, then a 1 in day4, and nothing in day 5, and arrive at&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;an end_date=01/04/2015? &amp;nbsp;Where does the date come from, what is "day" in relation to the date? &amp;nbsp;If its not a single "day" then probably best not to name it that, but something more descriptive.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  end_date=start_date;
  stop=1;
  if day1 ne . then end_date=end_date+1; else stop=0;
  if day2 ne . and stop then end_date=end_date+1;
  if day3 ne . and stop then end_date=end_date+1;
...
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Apr 2016 08:20:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/calculating-person-time/m-p/264732#M57811</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-04-19T08:20:19Z</dc:date>
    </item>
    <item>
      <title>Re: calculating person-time</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/calculating-person-time/m-p/264861#M57822</link>
      <description>&lt;P&gt;Thanks Freelance Reinhard! &amp;nbsp;I really appreciate your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Apr 2016 18:53:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/calculating-person-time/m-p/264861#M57822</guid>
      <dc:creator>sophia_SAS</dc:creator>
      <dc:date>2016-04-19T18:53:48Z</dc:date>
    </item>
  </channel>
</rss>

