<?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: How to code a look back period to create a history of disease indicator in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-code-a-look-back-period-to-create-a-history-of-disease/m-p/963778#M375412</link>
    <description>&lt;P&gt;The RETAIN approach you describe sounds reasonable to me.&amp;nbsp; Have you tried it?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please post the example data as a data step reading in the data with CARDS statement, and please post the coded you have tried. And please describe whether the code you tried is giving you errors, or just incorrect results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Posting the data and the code you have tried will help others help you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW, if you don't want the contemporaneous HYPERTENSION variable to impact HT_LOOKBACK (i.e. you only want to consider preceding observations, then just reorder two statements, so that you would have:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  ht_lookback= (visitdate&amp;lt;=cutoff_date) ;
  if hypertension=1 then cutoff_date = intnx('year',visitdate,1,'same') ;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 09 Apr 2025 01:01:02 GMT</pubDate>
    <dc:creator>Quentin</dc:creator>
    <dc:date>2025-04-09T01:01:02Z</dc:date>
    <item>
      <title>How to code a look back period to create a history of disease indicator</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-code-a-look-back-period-to-create-a-history-of-disease/m-p/963766#M375411</link>
      <description>&lt;P&gt;Hello, I am trying to figure out the best way to program in SAS a way to do a "look-back" where I can apply a patient's history of different health conditions to more recent visits, in particular in the event the patient has missing diagnosis data for some visits. I would like to implement a 1-year "look-back" period to see if a patient has had a history of different diseases and indicate that in a new 0/1 or Yes/No variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The term lookback may be a misnomer where I believe the best way to program this in SAS would to be to sort by patient ID and visit date use a RETAIN statement in a data step and then retain this value for a year if Hypertension=1. But if there is a better way to program this in SAS then that would be great too.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working with medical visit data where I have unique patient ID, data of visit, and a dummy variable indicator for presence of hypertension recorded at that visit. I have provided some example data below, and included the desired outcome in the column Hypertension_Lookback for a 1-year lookback period. In this example Patient 1 would have more recent visits where Hypertension_Lookback=1, as would Patient 2 for their most recent visit, but not their earlier visit before their first recorded instance of hypertension. Additionally, if I am using a 1-year cutoff, patient 5 would not have a history of hypertension indicated as the most recent visit was more than 1 year from the last visit with an indicator of Hypertension.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;PatientId&lt;/TD&gt;&lt;TD&gt;VisitDate&lt;/TD&gt;&lt;TD&gt;Hypertension&lt;/TD&gt;&lt;TD&gt;Hypertension_Lookback&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1/1/2023&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2/1/2023&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;3/1/2023&lt;/TD&gt;&lt;TD&g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&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Apr 2025 19:15:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-code-a-look-back-period-to-create-a-history-of-disease/m-p/963766#M375411</guid>
      <dc:creator>brian93</dc:creator>
      <dc:date>2025-04-08T19:15:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to code a look back period to create a history of disease indicator</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-code-a-look-back-period-to-create-a-history-of-disease/m-p/963778#M375412</link>
      <description>&lt;P&gt;The RETAIN approach you describe sounds reasonable to me.&amp;nbsp; Have you tried it?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please post the example data as a data step reading in the data with CARDS statement, and please post the coded you have tried. And please describe whether the code you tried is giving you errors, or just incorrect results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Posting the data and the code you have tried will help others help you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW, if you don't want the contemporaneous HYPERTENSION variable to impact HT_LOOKBACK (i.e. you only want to consider preceding observations, then just reorder two statements, so that you would have:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  ht_lookback= (visitdate&amp;lt;=cutoff_date) ;
  if hypertension=1 then cutoff_date = intnx('year',visitdate,1,'same') ;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 Apr 2025 01:01:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-code-a-look-back-period-to-create-a-history-of-disease/m-p/963778#M375412</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2025-04-09T01:01:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to code a look back period to create a history of disease indicator</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-code-a-look-back-period-to-create-a-history-of-disease/m-p/963799#M375425</link>
      <description>&lt;P&gt;What is the date from which you're looking back? Is it the same for each person?&amp;nbsp; Below I'm just assuming you have some variable like 'indexdate' which is your end of lookback.&amp;nbsp; I usually do this kind of thing in SQL if it's just a few conditions.&amp;nbsp; The below uses the useful (and slightly disconcerting) fact that PROC SQL doesn't complain about division by zero, so dividing by the 0/1 variable hypertension preserves this part: (indexdate-365&amp;lt;=visitdate&amp;lt;indexdate) as either 0 or 1 if hypertension=1 and forces it to missing otherwise.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table LB as
select patient, indexdate, 
max((indexdate-365&amp;lt;=visitdate&amp;lt;indexdate)/hypertension) as LB_hypertension
from have group by patient, indexdate;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 08 Apr 2025 23:07:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-code-a-look-back-period-to-create-a-history-of-disease/m-p/963799#M375425</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2025-04-08T23:07:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to code a look back period to create a history of disease indicator</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-code-a-look-back-period-to-create-a-history-of-disease/m-p/963802#M375426</link>
      <description>&lt;P&gt;Yes, RETAIN is a good way to go, assuming the data are sorted by ID/visitdate.&amp;nbsp; For each obs, just retain a cutoff date representing the 1 year window you want to examine for upcoming observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 input PatientId	VisitDate :mmddyy10.	Hypertension	Hypertension_Lookback;
 format visitdate mmddyy10.;
datalines;
1	1/1/2023	1	1
1	2/1/2023	0	1
1	3/1/2023	0	1
2	1/1/2023	0	0
2	2/1/2023	1	1
2	3/1/2023	0	1
3	1/1/2023	1	1
3	2/1/2023	1	1
4	1/1/2023	0	0
4	2/1/2023	0	0
5	1/1/2023	1	1
5	2/1/2024	0	0
run;
data want (drop=_:);
  set have;
  by patientid;

  retain _cutoff_date;
  if first.patientid then call missing(cutoff_date);
  if hypertension=1 then cutoff_date=intnx('year',visitdate,1,'same');

  ht_lookback= (visitdate&amp;lt;=cutoff_date);
run;
  
    
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2025 18:51:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-code-a-look-back-period-to-create-a-history-of-disease/m-p/963802#M375426</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2025-04-09T18:51:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to code a look back period to create a history of disease indicator</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-code-a-look-back-period-to-create-a-history-of-disease/m-p/963803#M375427</link>
      <description>So what is your desired output ?</description>
      <pubDate>Wed, 09 Apr 2025 01:13:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-code-a-look-back-period-to-create-a-history-of-disease/m-p/963803#M375427</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-04-09T01:13:08Z</dc:date>
    </item>
  </channel>
</rss>

