<?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: Date difference across rows (same patient, different variables) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Date-difference-across-rows-same-patient-different-variables/m-p/648219#M194127</link>
    <description>&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/254033"&gt;@biopharma&lt;/a&gt;&amp;nbsp;!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for such an in-depth analysis of my question.&amp;nbsp;&lt;/P&gt;&lt;P&gt;As for your question:&amp;nbsp;&lt;/P&gt;&lt;P&gt;1) If I understand you correctly, no both days are not included.&amp;nbsp;&lt;BR /&gt;Therefore, if the general appointment occurs on 15MAY2020 and the plastic surgery occurs on 16MAY2020, the date difference is 1. Whereas, if both appointment and surgery occur on the same day (15MAY2020), the date difference is 0.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;2) Yes, we would like to look into if the patient is followed up with subsequent plastic surgery.&lt;BR /&gt;(i.e. mastopexy is a correction surgery that helps with sagging, date from initial surgery until the mastopexy would be looked at in later analyses. Or, date from general appointment to mastopexy may be important as a measure of quality care)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3) Yes there can be a general appointment in between plastic surgery occurrences.&amp;nbsp;&lt;BR /&gt;(i.e. it may be in the form of a consultation with a medical oncologist should the woman find a tumour/lump after plastic surgery. Although uncommon, a trajectory may include 1) plastic surgery consultation 2) plastic surgery 3) general appointment with family physician 4) after referral consultation with an oncologist 5) surgery to remove tumour 6) plastic surgery to maintain shape of breast)&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 16 May 2020 00:20:19 GMT</pubDate>
    <dc:creator>deengyn</dc:creator>
    <dc:date>2020-05-16T00:20:19Z</dc:date>
    <item>
      <title>Date difference across rows (same patient, different variables)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-difference-across-rows-same-patient-different-variables/m-p/647806#M193907</link>
      <description>&lt;P&gt;Hi everyone,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm having a bit of trouble formulating what I want to do; I have some idea such as I will have to incorporate aspects such as "IS NOT NULL" but am unsure what general code format I should look into.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Summary_cod, in this case, represents access to a general appointment.&lt;/P&gt;&lt;P&gt;Pl_code represents the date in which the patient received a plastic surgery regarding the breast area.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Within the same patient, I'd like to look at the date difference between the date of the most recent general appointment and the first incidence of plastic surgery thereafter.&amp;nbsp;&amp;nbsp;&lt;BR /&gt;i.e. Patient #51, I'd like to find the date difference between OBS 1 and OBS3, whereas Patient #205 I'd like to find the date difference between OBS 5 and OBS 6.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Date Diff.png" style="width: 260px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/39439iD97BF45014EC0608/image-size/large?v=v2&amp;amp;px=999" role="button" title="Date Diff.png" alt="Date Diff.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The original code can be found here:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*First dataset (identifying general appointments and labelling type of appointment recieved);&lt;BR /&gt;proc sql;
CREATE TABLE t1a
		AS 
		SELECT
 		   pid,
 		   cod_act,
		   rec_num,
		   serv_date,
	   FROM tablea
	   WHERE
   			pro_spec = '07'
  		 	AND ( cod_act = '01201'
         		 OR cod_act = '01205')
		ORDER BY
		    pid,
		    serv_date;
		quit;

data t1b;
	set t1a;
	length summary_cod$4; 
	if cod_act = '01205' then summary_cod = 'BR'; 
	if cod_act = '01201' then summary_cod = 'SBR'; 
        run; 
&lt;BR /&gt;*Second dataset (identifying patients who recieved breast-related plastic surgery); 
proc sql;
CREATE TABLE plastic
		AS 
		SELECT
 		   pid,
 		   cod_act,
		   rec_num,
		   serv_date,
	   FROM tablep
	   WHERE
   			pro_spec = '09'
  		 	AND ( cod_act = '01434'
         		 OR cod_act = '01465'
                         OR cod_act = '01408' 
                         OR cod_act = '01403' )
		ORDER BY
		    pid,
		    serv_date;
		quit;

data pl1;
	set plastic;
	length pl_cod$10; 
	if cod_act = '01434' then pl_cod = 'reduction';
	if cod_act = '01465' then pl_cod = 'mastopexy';
        if cod_act = '01408' then pl_cod = 'removal';
        if cod_act = '01403' then pl_cod = 'nipple';
        run; 

*Stacking the appointment codes with the plastic surgery codes;
		data plbr;
		set t1b pl1;
		run;

*Formatting;
		proc sort data = plbr
		out = plb_sorted;
		by pid serv_date rec_num ; 
		run; 



&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 May 2020 14:16:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-difference-across-rows-same-patient-different-variables/m-p/647806#M193907</guid>
      <dc:creator>deengyn</dc:creator>
      <dc:date>2020-05-14T14:16:06Z</dc:date>
    </item>
    <item>
      <title>Re: Date difference across rows (same patient, different variables)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-difference-across-rows-same-patient-different-variables/m-p/647807#M193908</link>
      <description>&lt;P&gt;Please post example data in usable form, in a data step with datalines, and post the code in a window opened with the "little running man" icon; it is very hard to code for pictures.&lt;/P&gt;</description>
      <pubDate>Thu, 14 May 2020 13:37:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-difference-across-rows-same-patient-different-variables/m-p/647807#M193908</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-05-14T13:37:46Z</dc:date>
    </item>
    <item>
      <title>Re: Date difference across rows (same patient, different variables)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-difference-across-rows-same-patient-different-variables/m-p/647810#M193909</link>
      <description>&lt;P&gt;Untested code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by pid;
retain date_1;
if first.pid then date_1 = .;
if summary_cod ne "" then date_1 = serv_date;
if summary_cod = "" and pl_cod ne "" and date_1 ne .
then do;
  diff = serv_date - date_1;
  output;
  date_1 = .;
end;
drop date_1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 May 2020 13:41:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-difference-across-rows-same-patient-different-variables/m-p/647810#M193909</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-05-14T13:41:38Z</dc:date>
    </item>
    <item>
      <title>Re: Date difference across rows (same patient, different variables)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-difference-across-rows-same-patient-different-variables/m-p/647828#M193916</link>
      <description>Apologies, I've since added my code to describe my data structure.&lt;BR /&gt;I will keep this in mind for subsequent posts as well!</description>
      <pubDate>Thu, 14 May 2020 14:43:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-difference-across-rows-same-patient-different-variables/m-p/647828#M193916</guid>
      <dc:creator>deengyn</dc:creator>
      <dc:date>2020-05-14T14:43:31Z</dc:date>
    </item>
    <item>
      <title>Re: Date difference across rows (same patient, different variables)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-difference-across-rows-same-patient-different-variables/m-p/647862#M193927</link>
      <description>&lt;P&gt;Can really use code for the input dataset. I have created for the first patient. A couple of questions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. For DIFF, are both dates included - most recent general visit and first plastic procedure? You will need to add a day to it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. Once a procedure is done, do you care about DIFF value for a later procedure for the same patient?&lt;/P&gt;&lt;P&gt;3. Could there be a general visit between procedures? If the dataset is pre-sorted by PID and DATE then the solution could be simpler.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The above are unknown so the solution is based on some assumptions on my part.&lt;/P&gt;&lt;PRE&gt;data have ;
   infile datalines missover ;
   length pid 8 serv_date 8 summary_cod $3 pl_cod $12 ;
   format serv_date date9. ;
   input pid serv_date:date9. summary_cod $ pl_cod $ ;
   datalines ;
51 26SEP2017 BR .
51 25SEP2017 SBR .
51 19MAR2018 . removal
51 19MAR2018 . mastopexy
;
run ;

data want ;
   do until (last.pid) ;
      set have ;
      by pid ;
      format recent_date date9. ;
      if not missing(summary_cod) then recent_date = max(serv_date,recent_date) ;
      if not missing(pl_cod) and nmiss(diff,done)=2 then 
         do ;
            diff = serv_date-recent_date ;   
            done = 1 ;
         end ;
      *else diff = . ;
      output ;
   end ;
run ;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 May 2020 16:02:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-difference-across-rows-same-patient-different-variables/m-p/647862#M193927</guid>
      <dc:creator>biopharma</dc:creator>
      <dc:date>2020-05-14T16:02:26Z</dc:date>
    </item>
    <item>
      <title>Re: Date difference across rows (same patient, different variables)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-difference-across-rows-same-patient-different-variables/m-p/648219#M194127</link>
      <description>&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/254033"&gt;@biopharma&lt;/a&gt;&amp;nbsp;!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for such an in-depth analysis of my question.&amp;nbsp;&lt;/P&gt;&lt;P&gt;As for your question:&amp;nbsp;&lt;/P&gt;&lt;P&gt;1) If I understand you correctly, no both days are not included.&amp;nbsp;&lt;BR /&gt;Therefore, if the general appointment occurs on 15MAY2020 and the plastic surgery occurs on 16MAY2020, the date difference is 1. Whereas, if both appointment and surgery occur on the same day (15MAY2020), the date difference is 0.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;2) Yes, we would like to look into if the patient is followed up with subsequent plastic surgery.&lt;BR /&gt;(i.e. mastopexy is a correction surgery that helps with sagging, date from initial surgery until the mastopexy would be looked at in later analyses. Or, date from general appointment to mastopexy may be important as a measure of quality care)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3) Yes there can be a general appointment in between plastic surgery occurrences.&amp;nbsp;&lt;BR /&gt;(i.e. it may be in the form of a consultation with a medical oncologist should the woman find a tumour/lump after plastic surgery. Although uncommon, a trajectory may include 1) plastic surgery consultation 2) plastic surgery 3) general appointment with family physician 4) after referral consultation with an oncologist 5) surgery to remove tumour 6) plastic surgery to maintain shape of breast)&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 16 May 2020 00:20:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-difference-across-rows-same-patient-different-variables/m-p/648219#M194127</guid>
      <dc:creator>deengyn</dc:creator>
      <dc:date>2020-05-16T00:20:19Z</dc:date>
    </item>
    <item>
      <title>Re: Date difference across rows (same patient, different variables)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-difference-across-rows-same-patient-different-variables/m-p/648313#M194171</link>
      <description>Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/326508"&gt;@deengyn&lt;/a&gt;,&lt;BR /&gt;&lt;BR /&gt;This is helpful but need more answers. As a preliminary step, you can take my program for the first patient and add 1 or 2 more patients with the data that you currently HAVE. Next, let us also know what you would like to see as the end result of that dataset with DIFF generated. Let us keep this to convention and call it the WANT dataset.&lt;BR /&gt;&lt;BR /&gt;From what you have clarified in (2) above, I see that you may need more than one DIFF value. DIFF1 - from General Visit. DIFF2 from Initial Surgery. Finally, from (3) would you be able to add a sample patient to cover that scenario and how it would affect DIFF(s) values. You would also need to generate the WANT dataset with code similar to the one I provided for generating the HAVE dataset above.&lt;BR /&gt;&lt;BR /&gt;One last piece. The dataset (picture) from your first post does NOT represent the code that you provided later. If that is the result of the sort below then for Patient 51, the first SERV_DATE value would be 25SEP2017.&lt;BR /&gt;&lt;BR /&gt;*Formatting;&lt;BR /&gt;proc sort data = plbr&lt;BR /&gt;out = plb_sorted;&lt;BR /&gt;by pid serv_date rec_num ;&lt;BR /&gt;run;&lt;BR /&gt;</description>
      <pubDate>Sat, 16 May 2020 16:24:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-difference-across-rows-same-patient-different-variables/m-p/648313#M194171</guid>
      <dc:creator>biopharma</dc:creator>
      <dc:date>2020-05-16T16:24:11Z</dc:date>
    </item>
  </channel>
</rss>

