<?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 Duration (Index Date to Time-to-Event) with Competing Risks in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Duration-Index-Date-to-Time-to-Event-with-Competing/m-p/857832#M338958</link>
    <description>&lt;P&gt;You should provide an example of what you want as output for your given example data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Earliest date, assuming you have SAS date values, is to use Min(death_date, hosp_admdate,ltc_admdate)&lt;/P&gt;
&lt;P&gt;If you want the interval between the earliest event and Index_date then&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;interval = Min(death_date, hosp_admdate,ltc_admdate) - index_date;&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;</description>
    <pubDate>Wed, 08 Feb 2023 19:12:20 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2023-02-08T19:12:20Z</dc:date>
    <item>
      <title>Calculate Duration (Index Date to Time-to-Event) with Competing Risks</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Duration-Index-Date-to-Time-to-Event-with-Competing/m-p/857783#M338941</link>
      <description>&lt;P&gt;Hi SAS communities,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am performing a survival analysis where the event of interest is outpatient prescription and competing risks include death, admission to hospital, and admission to long-term care. I have been trying to write a code to find the follow-up time for each individual in the study; however, some individuals experience more than one event, and I want to calculate time from the earliest event experienced, whether it be the event of interest or a competing risk.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is a simplified version of the dataset:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;index_date&lt;/TD&gt;&lt;TD&gt;prescription&lt;/TD&gt;&lt;TD&gt;service_date&lt;/TD&gt;&lt;TD&gt;death_date&lt;/TD&gt;&lt;TD&gt;hosp_admdate&lt;/TD&gt;&lt;TD&gt;LTC_admdate&lt;/TD&gt;&lt;TD&gt;death&lt;/TD&gt;&lt;TD&gt;hosp&lt;/TD&gt;&lt;TD&gt;LTC&lt;/TD&gt;&lt;TD&gt;censor&lt;/TD&gt;&lt;TD&gt;censdate&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;001&lt;/TD&gt;&lt;TD&gt;09Sep2019&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;16Dec2019&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;002&lt;/TD&gt;&lt;TD&gt;01Feb2019&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;19Jun2019&lt;/TD&gt;&lt;TD&gt;06Jul2019&lt;/TD&gt;&lt;TD&gt;08May2019&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I found a code online which creates a censor variable and censdate based on the event, I am just not sure how to modify this code so that it captures the multiple competing risks and takes only the earliest event as the censdate.&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot (807).png" style="width: 709px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/80213i6A4F6E5F90A6EA98/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot (807).png" alt="Screenshot (807).png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2023 16:20:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Duration-Index-Date-to-Time-to-Event-with-Competing/m-p/857783#M338941</guid>
      <dc:creator>mels9808</dc:creator>
      <dc:date>2023-02-08T16:20:04Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Duration (Index Date to Time-to-Event) with Competing Risks</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Duration-Index-Date-to-Time-to-Event-with-Competing/m-p/857832#M338958</link>
      <description>&lt;P&gt;You should provide an example of what you want as output for your given example data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Earliest date, assuming you have SAS date values, is to use Min(death_date, hosp_admdate,ltc_admdate)&lt;/P&gt;
&lt;P&gt;If you want the interval between the earliest event and Index_date then&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;interval = Min(death_date, hosp_admdate,ltc_admdate) - index_date;&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;</description>
      <pubDate>Wed, 08 Feb 2023 19:12:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Duration-Index-Date-to-Time-to-Event-with-Competing/m-p/857832#M338958</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-02-08T19:12:20Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Duration (Index Date to Time-to-Event) with Competing Risks</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Duration-Index-Date-to-Time-to-Event-with-Competing/m-p/857834#M338960</link>
      <description>&lt;P&gt;I was hoping to obtain some sort of variable that identifies the event that occurred first for the individual. For example, if death occurred first then censor=1, if hospitalization occurred first then censor=2, and if both death and hospitalization occurred but death occurred first then censor=1. I also wanted a variable that identifies the censoring date that corresponds to the date the earliest event occurred. I was then hoping to calculate follow-up time by doing censdate-index_date for each subject.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2023 19:33:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Duration-Index-Date-to-Time-to-Event-with-Competing/m-p/857834#M338960</guid>
      <dc:creator>mels9808</dc:creator>
      <dc:date>2023-02-08T19:33:35Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Duration (Index Date to Time-to-Event) with Competing Risks</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Duration-Index-Date-to-Time-to-Event-with-Competing/m-p/857891#M338973</link>
      <description>&lt;P&gt;I will repeat: please show what you expect for your example data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your "censoring date that corresponds to the date the earliest event " is the MIN of those variables. The Min function will only return missing if all the variables have missing values.&lt;/P&gt;
&lt;P&gt;There is a WHICHN, and for character values, WHICHC, that returns a position of a value from a given list. So that can be used. But we need to see just what you expect to see in the data set to show example code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have to say that I feel like you are missing something when you state: ". For example, if death occurred first then censor=1, if hospitalization occurred first then censor=2, and if both death and hospitalization occurred but death occurred first then censor=1." There is nothing in the "if both" that modifies the result given by the first two values. Plus you said you have 3 dates/ events. Do I have &lt;STRONG&gt;guess&lt;/STRONG&gt; that the third event is Censor=3?? Guessing is a poor way to program.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2023 21:08:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Duration-Index-Date-to-Time-to-Event-with-Competing/m-p/857891#M338973</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-02-08T21:08:38Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Duration (Index Date to Time-to-Event) with Competing Risks</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Duration-Index-Date-to-Time-to-Event-with-Competing/m-p/858050#M339020</link>
      <description>&lt;P&gt;This is what I am hoping to see in my data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;index_date&lt;/TD&gt;&lt;TD&gt;prescription&lt;/TD&gt;&lt;TD&gt;service_date&lt;/TD&gt;&lt;TD&gt;death_date&lt;/TD&gt;&lt;TD&gt;hosp_admdate&lt;/TD&gt;&lt;TD&gt;LTC_admdate&lt;/TD&gt;&lt;TD&gt;death&lt;/TD&gt;&lt;TD&gt;hosp&lt;/TD&gt;&lt;TD&gt;LTC&lt;/TD&gt;&lt;TD&gt;censor&lt;/TD&gt;&lt;TD&gt;censdate&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;001&lt;/TD&gt;&lt;TD&gt;09Sep2019&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;16Dec2019&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;16Dec2019&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&l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&lt;TD&gt;01Mar2019&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;09Feb2019&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Service_date: date of prescription. End of study date: 10Mar2020.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If first event=prescription, censor=0 and censdate=service_date.&lt;/P&gt;&lt;P&gt;If first event=death, censor=1 and censdate=death_date.&lt;/P&gt;&lt;P&gt;If first event=hospitalization, censor=2 and censdate=hosp_admdate.&lt;/P&gt;&lt;P&gt;If first event=LTC, censor=3 and censdate=LTC_admdate.&lt;/P&gt;&lt;P&gt;If no events were experienced and subjects were followed until end of study, censor=4 and censdate=end of study date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope this clears things up!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Feb 2023 15:27:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Duration-Index-Date-to-Time-to-Event-with-Competing/m-p/858050#M339020</guid>
      <dc:creator>mels9808</dc:creator>
      <dc:date>2023-02-09T15:27:33Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Duration (Index Date to Time-to-Event) with Competing Risks</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Duration-Index-Date-to-Time-to-Event-with-Competing/m-p/858224#M339088</link>
      <description>&lt;P&gt;You should present your example data as a data step, like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;                                                                                                                              
length ID $3                                                                                                                            
       index_date                                                                                                                       
       prescription                                                                                                                     
       service_date                                                                                                                     
       death_date                                                                                                                       
       hosp_admdate                                                                                                                     
       LTC_admdate                                                                                                                      
       death                                                                                                                            
       hosp                                                                                                                             
       LTC  8;                                                                                                                          
  informat                                                                                                                              
       index_date                                                                                                                       
       service_date                                                                                                                     
       death_date                                                                                                                       
       hosp_admdate                                                                                                                     
       LTC_admdate  date9.;                                                                                                             
  format                                                                                                                                
       index_date                                                                                                                       
       service_date                                                                                                                     
       death_date                                                                                                                       
       hosp_admdate                                                                                                                     
       LTC_admdate date9.;                                                                                                              
infile cards truncover;                                                                                                                 
input ID--LTC;                                                                                                                          
cards;                                                                                                                                  
001 09Sep2019 0 .      16Dec2019      .      .      1      0      0                                                                     
002 01Feb2019 1 19Jun2019      06Jul2019      08May2019      .      1      1      0                                                     
003 06Dec2020 0 .      .      .      .      0      0      0                                                                             
004 01Mar2020 1 05Mar2020      .      .      09Feb2020      0      0      1                                                             
005 02Dec2018 0 09Feb2019      .      01Mar2019      .      0      1      0                                                             
;run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can get the result you want like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;                                                                                                                              
  set have;                                                                                                                             
  censdate=min(service_date,death_date,hosp_admdate,LTC_admdate);                                                                       
  if missing(censdate) then do;                                                                                                         
    censor=4;                                                                                                                           
    censdate='10mar2020'd; /* end of study */                                                                                           
    end;                                                                                                                                
  else if censdate=death_date then                                                                                                      
    censor=1;                                                                                                                           
  else if censdate=hosp_admdate then                                                                                                    
    censor=2;                                                                                                                           
  else if censdate=LTC_admdate then                                                                                                     
    censor=3;                                                                                                                           
  else censor=0;                                                                                                                        
  format censdate date9.;                                                                                                               
run;         
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You did not describe what to do if e.g. both hospital admission and death happen on the same date - in this case death will be the end result (censor=1), as that comes first in the code. If you want different priorities, you will have to rearrange the code a bit.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2023 10:19:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Duration-Index-Date-to-Time-to-Event-with-Competing/m-p/858224#M339088</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2023-02-10T10:19:41Z</dc:date>
    </item>
  </channel>
</rss>

