<?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: Tying an event to a date in a row (for each specific member) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Tying-an-event-to-a-date-in-a-row-for-each-specific-member/m-p/848636#M335508</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp; -I agree with you but unfortunately the real data is similar to the format I presented with additional other vars. I was actually&amp;nbsp; programming to&amp;nbsp; use a proc contents to get all the date variables and then do a proc transpose to reshape the data in the format you propose when I saw your comments.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was seeing if there was a more efficient&amp;nbsp; method to not reshape the data.&amp;nbsp; I think not.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Lawrence&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 08 Dec 2022 19:41:27 GMT</pubDate>
    <dc:creator>LB</dc:creator>
    <dc:date>2022-12-08T19:41:27Z</dc:date>
    <item>
      <title>Tying an event to a date in a row (for each specific member)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Tying-an-event-to-a-date-in-a-row-for-each-specific-member/m-p/848613#M335503</link>
      <description>&lt;P&gt;Hi-the imagined dataset is below -the goal is tie a specific event&amp;nbsp; to the first date in which something happened-&lt;/P&gt;
&lt;P&gt;In this example, the censor events happen in chronological order-either the event happened, death, or EOF (end of follow up).&lt;/P&gt;
&lt;P&gt;It takes the first date that a censor event occurred or uses 30 days after the discharge date if no event occurred.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have proc sql code&amp;nbsp; below that&amp;nbsp; &amp;nbsp;uses&amp;nbsp; when statements. This is fine for 2 events (event1 and death)&amp;nbsp; but this would be cumbersome if there 10-20 events. Not sure if there is a more efficient way in that if time 5 is used it corresponds to event 5 and if all&amp;nbsp; event (and death) dates&amp;nbsp; are&amp;nbsp; null then&amp;nbsp; simply takes the 30 days after the discharge&amp;nbsp; and gives it the proper category of 'eof' or something to that effect.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It can be either datastep or sql-either one.&lt;/P&gt;
&lt;P&gt;TIA.&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   ID  8.	 Discharge MMDDYY10. EVENT 8.  EVENT_DT MMDDYY10. DEATH 8. DEATH_DT MMDDYY10.;
	input   ID  	 Discharge  EVENT  EVENT_DT DEATH  DEATH_DT ;
	format Discharge DDMMYY10.  EVENT_DT DDMMYY10. Death_dt DDMMYY10. ;
datalines;
1 01/01/2020 1 01/15/2020 0 01/20/2020
2 01/01/2020 0 .          1 01/17/2020
3 01/01/2020 0 .          0 . 

 ;
run;

proc sql; 

select a.*,
min(EVENT_DT,DEATH_DT, intnx('DAY', Discharge,30)) format=date9. as censor_DATE,
case when EVENT=1 then 'EVENT'
when EVENT=0 AND DEATH=1 THEN 'DEATH'
when EVENT=0 AND DEATH=0 THEN 'EOF ' END as censor_event    
from have A;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Dec 2022 19:10:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Tying-an-event-to-a-date-in-a-row-for-each-specific-member/m-p/848613#M335503</guid>
      <dc:creator>LB</dc:creator>
      <dc:date>2022-12-08T19:10:54Z</dc:date>
    </item>
    <item>
      <title>Re: Tying an event to a date in a row (for each specific member)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Tying-an-event-to-a-date-in-a-row-for-each-specific-member/m-p/848619#M335505</link>
      <description>&lt;P&gt;Can you please make up an example that has 10 events and explain in words exactly what the desired result is?&lt;/P&gt;</description>
      <pubDate>Thu, 08 Dec 2022 19:30:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Tying-an-event-to-a-date-in-a-row-for-each-specific-member/m-p/848619#M335505</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-12-08T19:30:44Z</dc:date>
    </item>
    <item>
      <title>Re: Tying an event to a date in a row (for each specific member)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Tying-an-event-to-a-date-in-a-row-for-each-specific-member/m-p/848620#M335506</link>
      <description>&lt;P&gt;Wouldn't it make more sense to start with the data in more natural configuration?&lt;/P&gt;
&lt;P&gt;Something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data visits;
  input id visit $ date :mmddyy. ;
  format date yymmdd10.;
cards;
1 DISCHARGE 01/01/2020 
1 EVENT     01/15/2020
1 FOLLOW_UP 01/20/2020
2 DISCHARGE 01/01/2020 
2 DEATH     01/17/2020
3 DISCHARGE 01/01/2020
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you could just process it by ID and DATE to figure out whatever it was you wanted to calculate.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Dec 2022 19:35:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Tying-an-event-to-a-date-in-a-row-for-each-specific-member/m-p/848620#M335506</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-12-08T19:35:03Z</dc:date>
    </item>
    <item>
      <title>Re: Tying an event to a date in a row (for each specific member)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Tying-an-event-to-a-date-in-a-row-for-each-specific-member/m-p/848636#M335508</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp; -I agree with you but unfortunately the real data is similar to the format I presented with additional other vars. I was actually&amp;nbsp; programming to&amp;nbsp; use a proc contents to get all the date variables and then do a proc transpose to reshape the data in the format you propose when I saw your comments.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was seeing if there was a more efficient&amp;nbsp; method to not reshape the data.&amp;nbsp; I think not.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Lawrence&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Dec 2022 19:41:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Tying-an-event-to-a-date-in-a-row-for-each-specific-member/m-p/848636#M335508</guid>
      <dc:creator>LB</dc:creator>
      <dc:date>2022-12-08T19:41:27Z</dc:date>
    </item>
    <item>
      <title>Re: Tying an event to a date in a row (for each specific member)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Tying-an-event-to-a-date-in-a-row-for-each-specific-member/m-p/848647#M335511</link>
      <description>&lt;P&gt;The way to handle multiple variables in a similar way is with ARRAY in a data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;So you have one array of the FLAG variables that indicate whether or not the event occurred. Another array of the date variables.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am not sure I understand your logic but if you wanted to calculate some type of right censored survival variable for many different possible events then it should be possible.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is the goal to calculate the FIRST event type that occurred and if none occurred then use the max follow up date plus 30?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  array flags event death ;
  array dates event_dt&amp;nbsp;death_dt&amp;nbsp;;
&amp;nbsp;&amp;nbsp;length&amp;nbsp;event_type&amp;nbsp;$32 date_to_use&amp;nbsp;8;
  format date_to_use yymmdd10.;
  date_to_use=max(of dates[*]);
&amp;nbsp;&amp;nbsp;do&amp;nbsp;index=1&amp;nbsp;to&amp;nbsp;dim(flags);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;flags[index]&amp;nbsp;and dates[index]&amp;lt;date_to_use then do;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;event_type=vname(flags[index]);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;date_to_use=dates[index];
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end;
&amp;nbsp;&amp;nbsp;end;
  censored= (event_type=' ');
  if censored then data_to_use=date_to_use +30;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Dec 2022 19:57:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Tying-an-event-to-a-date-in-a-row-for-each-specific-member/m-p/848647#M335511</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-12-08T19:57:09Z</dc:date>
    </item>
    <item>
      <title>Re: Tying an event to a date in a row (for each specific member)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Tying-an-event-to-a-date-in-a-row-for-each-specific-member/m-p/848651#M335512</link>
      <description>Thanks- This a bit closer to what I was thinking.   But yes the goal is to calculate the first event and then if -nothing else actually use just use the discharge date plus  30 days. Can def play with this code a bit to get what I need.</description>
      <pubDate>Thu, 08 Dec 2022 20:09:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Tying-an-event-to-a-date-in-a-row-for-each-specific-member/m-p/848651#M335512</guid>
      <dc:creator>LB</dc:creator>
      <dc:date>2022-12-08T20:09:13Z</dc:date>
    </item>
  </channel>
</rss>

