<?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: Calculate time to event from longitudinal data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calculate-time-to-event-from-longitudinal-data/m-p/837177#M331014</link>
    <description>&lt;P&gt;You have 3 conditions specified, but only provide two IDs. We can't be sure we have programmed all three conditions because we don't have data for the third condition. In the future, we need data that represents all reasonable situations that might happen. However, you can test it out on other conditions to see if it works.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, I did not compute the variable censor_status and I leave it as a homework problem for you to do so, given the logic of the program, I don't think it will be hard.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    by id;
    retain start_date end_date;
    if first.id then do;
        start_date=visit_date;
        end_date=.;
    end;
    if disease=1 and missing(end_date) then end_date=visit_date;
    if last.id and missing(end_date) then end_date=visit_date;
    if last.id and not missing(death_date) then end_date=death_date;
    if last.id then do;
        time_to_event=end_date-start_date;
        output;
    end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 06 Oct 2022 14:46:51 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2022-10-06T14:46:51Z</dc:date>
    <item>
      <title>Calculate time to event from longitudinal data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-time-to-event-from-longitudinal-data/m-p/837111#M330996</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the data like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;infile datalines delimiter=',';&lt;BR /&gt;attrib&lt;BR /&gt;id length=$1&lt;BR /&gt;visit_date format=date9. informat=date9.&lt;BR /&gt;death_date format=date9. informat=date9.&lt;BR /&gt;;&lt;BR /&gt;input id $ visit_date death death_date disease;&lt;BR /&gt;*format id best. visit_date death_date date9.;&lt;BR /&gt;datalines;&lt;BR /&gt;1,24oct2012,0,.,0&lt;BR /&gt;1,24oct2013,0,.,0&lt;BR /&gt;1,23oct2014,0,.,0&lt;BR /&gt;1,26oct2015,0,.,0&lt;BR /&gt;1,23oct2016,0,.,1&lt;BR /&gt;1,28oct2017,0,.,1&lt;BR /&gt;2,20dec2007,1,15jun2018,0&lt;BR /&gt;2,17sep2008,1,15jun2018,0&lt;BR /&gt;2,20dec2009,1,15jun2018,0&lt;BR /&gt;2,16sep2010,1,15jun2018,1&lt;BR /&gt;2,20dec2011,1,15jun2018,1&lt;BR /&gt;2,22sep2012,1,15jun2018,1&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From this longitudinal dataset, I want to generate the dataset to run Cox model with competing risk. More specifically, I want to create the dataset that satisfy the following:&lt;/P&gt;&lt;P&gt;- if from the first visit to the last visit, subject does not have the event (disease=0), then time_to_event= duration from the first visit to the last visit and create variable called censor_status=0.&lt;/P&gt;&lt;P&gt;- if from the first visit to the last visit, subject has the event in between (diease=1), then time_to_event =duration from first visit to the visit_date when even happen (aka disease from 0 to 1) and censor_status=1.&lt;/P&gt;&lt;P&gt;- if death_date occurs before the event happens then time_to_event = duration from first visit to death date, and censor_status=2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any insight is greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Oct 2022 14:15:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-time-to-event-from-longitudinal-data/m-p/837111#M330996</guid>
      <dc:creator>qbui</dc:creator>
      <dc:date>2022-10-06T14:15:52Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate time to event from longitudinal data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-time-to-event-from-longitudinal-data/m-p/837115#M330998</link>
      <description>&lt;P&gt;Before you proceed, you should first learn the proper use of informats in INPUT statements.&lt;/P&gt;
&lt;P&gt;Right now, your data step does not work:&lt;/P&gt;
&lt;PRE&gt; 69         data have;
 70         input id visit_date death_date status;
 71         cards;
 
 NOTE: Invalid data for visit_date in line 72 3-11.
 REGEL:     ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0                     
 72         1 01jan2000 . 0
 id=1 visit_date=. death_date=. status=0 _ERROR_=1 _N_=1
&lt;/PRE&gt;
&lt;P&gt;(multiple NOTEs for invalid data removed).&lt;/P&gt;
&lt;P&gt;Since you use&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/lestmtsref/n0lrz3gb7m9e4rn137op544ddg0v.htm" target="_blank" rel="noopener"&gt;List INPUT&lt;/A&gt;&amp;nbsp;, you have to use the colon modifier when using informats. From the look of your data, you should use the DATE9. informat.&lt;/P&gt;
&lt;P&gt;Please fix your data step, so we can proceed in helping you further.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Oct 2022 06:56:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-time-to-event-from-longitudinal-data/m-p/837115#M330998</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-10-06T06:56:32Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate time to event from longitudinal data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-time-to-event-from-longitudinal-data/m-p/837172#M331012</link>
      <description>Hi Kurt_Bremser, Thank you for your reply. I just corrected the data step. I hope it works now. Your opinion is greatly appreciated.&lt;BR /&gt;Thanks</description>
      <pubDate>Thu, 06 Oct 2022 14:17:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-time-to-event-from-longitudinal-data/m-p/837172#M331012</guid>
      <dc:creator>qbui</dc:creator>
      <dc:date>2022-10-06T14:17:40Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate time to event from longitudinal data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-time-to-event-from-longitudinal-data/m-p/837177#M331014</link>
      <description>&lt;P&gt;You have 3 conditions specified, but only provide two IDs. We can't be sure we have programmed all three conditions because we don't have data for the third condition. In the future, we need data that represents all reasonable situations that might happen. However, you can test it out on other conditions to see if it works.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, I did not compute the variable censor_status and I leave it as a homework problem for you to do so, given the logic of the program, I don't think it will be hard.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    by id;
    retain start_date end_date;
    if first.id then do;
        start_date=visit_date;
        end_date=.;
    end;
    if disease=1 and missing(end_date) then end_date=visit_date;
    if last.id and missing(end_date) then end_date=visit_date;
    if last.id and not missing(death_date) then end_date=death_date;
    if last.id then do;
        time_to_event=end_date-start_date;
        output;
    end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Oct 2022 14:46:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-time-to-event-from-longitudinal-data/m-p/837177#M331014</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-10-06T14:46:51Z</dc:date>
    </item>
  </channel>
</rss>

