<?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: Find patient a diagnosis within a year of delivering a child in dataset where pt has multiple en in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Find-patient-a-diagnosis-within-a-year-of-delivering-a-child-in/m-p/470837#M120509</link>
    <description>&lt;P&gt;The hopeful output would be&lt;/P&gt;&lt;TABLE cellspacing="0" cellpadding="0" border="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Patient&lt;/TD&gt;&lt;TD&gt;Allconditionsmet&lt;/TD&gt;&lt;TD&gt;Year&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Patient x&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;TD&gt;2004&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Patient z&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;TD&gt;2001&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but if I can just create a flag for patients who meet all the criteria, I would be happy. Having the year return would be a bonus&lt;/P&gt;</description>
    <pubDate>Sun, 17 Jun 2018 01:47:03 GMT</pubDate>
    <dc:creator>jsimmo02</dc:creator>
    <dc:date>2018-06-17T01:47:03Z</dc:date>
    <item>
      <title>Find patient a diagnosis within a year of delivering a child in dataset where pt has multiple entrie</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-patient-a-diagnosis-within-a-year-of-delivering-a-child-in/m-p/470826#M120504</link>
      <description>&lt;P&gt;Hey there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I have a large patient dataset where patients often have multiple entries under the same patient ID. Each entry has a column for patient ID, year of admission, whether they are a smoker (0 = no, 1 = yes), and whether they were admitted to deliver a child (0=no, 1 =yes) so the data looks like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE cellspacing="0" cellpadding="0" border="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Patient&lt;/TD&gt;&lt;TD&gt;Year admitted&lt;/TD&gt;&lt;TD&gt;Smoking Flag&lt;/TD&gt;&lt;TD&gt;Delivery Flag&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Patient x&lt;/TD&gt;&lt;TD&gt;2002&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Patient x&lt;/TD&gt;&lt;TD&gt;2003&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Patient x&lt;/TD&gt;&lt;TD&gt;2004&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;Patient x&lt;/TD&gt;&lt;TD&gt;2006&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;Patient x&lt;/TD&gt;&lt;TD&gt;2008&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;Patient y&lt;/TD&gt;&lt;TD&gt;2004&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;Patient z&lt;/TD&gt;&lt;TD&gt;2001&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Patient z&lt;/TD&gt;&lt;TD&gt;2001&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I return a list of patients who smoked the year of or the year before delivering a child (as well as the year that it occured).&lt;/P&gt;</description>
      <pubDate>Sun, 17 Jun 2018 00:20:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-patient-a-diagnosis-within-a-year-of-delivering-a-child-in/m-p/470826#M120504</guid>
      <dc:creator>jsimmo02</dc:creator>
      <dc:date>2018-06-17T00:20:47Z</dc:date>
    </item>
    <item>
      <title>Re: Find patient a diagnosis within a year of delivering a child in dataset where pt has multiple en</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-patient-a-diagnosis-within-a-year-of-delivering-a-child-in/m-p/470828#M120505</link>
      <description>&lt;P&gt;Are these actually years or full dates?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming your data is sorted correctly:&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 patient year_admitted;

prev_smoke = lag(smoke);
prev_year = lag(year);

if first.patient then call missing(prev_smoke, prev_year);
smoke_prev_year = .;

if delivery_flag=1  /*if delivered*/
    and year-prev_year=1  /*if previous record is the previous year*/
     and (smoking_flag=1 or prev_smoke=1) /*smoked in current or previous year*/ 
           then smoke_prev_year = 1;
else if delivery_flag=1 then smoke_prev_year=0; /*only set flag if delivered*/


run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/85589"&gt;@jsimmo02&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hey there,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I have a large patient dataset where patients often have multiple entries under the same patient ID. Each entry has a column for patient ID, year of admission, whether they are a smoker (0 = no, 1 = yes), and whether they were admitted to deliver a child (0=no, 1 =yes) so the data looks like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;Patient&lt;/TD&gt;
&lt;TD&gt;Year admitted&lt;/TD&gt;
&lt;TD&gt;Smoking Flag&lt;/TD&gt;
&lt;TD&gt;Delivery Flag&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Patient x&lt;/TD&gt;
&lt;TD&gt;2002&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Patient x&lt;/TD&gt;
&lt;TD&gt;2003&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Patient x&lt;/TD&gt;
&lt;TD&gt;2004&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;Patient x&lt;/TD&gt;
&lt;TD&gt;2006&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;Patient x&lt;/TD&gt;
&lt;TD&gt;2008&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;Patient y&lt;/TD&gt;
&lt;TD&gt;2004&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;Patient z&lt;/TD&gt;
&lt;TD&gt;2001&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Patient z&lt;/TD&gt;
&lt;TD&gt;2001&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can I return a list of patients who smoked the year of or the year before delivering a child (as well as the year that it occured).&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 17 Jun 2018 00:26:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-patient-a-diagnosis-within-a-year-of-delivering-a-child-in/m-p/470828#M120505</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-06-17T00:26:06Z</dc:date>
    </item>
    <item>
      <title>Re: Find patient a diagnosis within a year of delivering a child in dataset where pt has multiple en</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-patient-a-diagnosis-within-a-year-of-delivering-a-child-in/m-p/470833#M120506</link>
      <description>&lt;P&gt;A couple of questions ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First, there are some years that don't appear.&amp;nbsp; For example, Patient X has no data for 2005.&amp;nbsp; Can we assume that smoker=no for those years?&amp;nbsp; (If not, how do we determine smoking status?)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Clearly, you want to flag this combination:&amp;nbsp; delivery=yes, smoker=yes, and smoker=yes for the previous year.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did you also want to flag:&amp;nbsp; delivery=yes, smoker=no, but smoker=yes for the previous year?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did you also want to flag:&amp;nbsp; delivery=yes, smoker=yes, but smoker=no for the previous year?&lt;/P&gt;</description>
      <pubDate>Sun, 17 Jun 2018 01:23:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-patient-a-diagnosis-within-a-year-of-delivering-a-child-in/m-p/470833#M120506</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-06-17T01:23:31Z</dc:date>
    </item>
    <item>
      <title>Re: Find patient a diagnosis within a year of delivering a child in dataset where pt has multiple en</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-patient-a-diagnosis-within-a-year-of-delivering-a-child-in/m-p/470834#M120507</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/85589"&gt;@jsimmo02&lt;/a&gt;&amp;nbsp; Can you please post a sample of your expect output for your input sample? Thank you&lt;/P&gt;</description>
      <pubDate>Sun, 17 Jun 2018 01:28:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-patient-a-diagnosis-within-a-year-of-delivering-a-child-in/m-p/470834#M120507</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-06-17T01:28:06Z</dc:date>
    </item>
    <item>
      <title>Re: Find patient a diagnosis within a year of delivering a child in dataset where pt has multiple en</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-patient-a-diagnosis-within-a-year-of-delivering-a-child-in/m-p/470836#M120508</link>
      <description>&lt;P&gt;First, there are some years that don't appear.&amp;nbsp; For example, Patient X has no data for 2005.&amp;nbsp; Can we assume that smoker=no for those years?&amp;nbsp; (If not, how do we determine smoking status?) &lt;STRONG&gt;Yes, you can assume smoker = no for those years.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"Clearly, you want to flag this combination:&amp;nbsp; delivery=yes, smoker=yes, and smoker=yes for the previous year."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;I am hoping for delivery = yes and (smoker=yes OR smoker for previous year = yes) &lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Did you also want to flag:&amp;nbsp; delivery=yes, smoker=no, but smoker=yes for the previous year? YES&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Did you also want to flag:&amp;nbsp; delivery=yes, smoker=yes, but smoker=no for the previous year? YES&lt;/P&gt;</description>
      <pubDate>Sun, 17 Jun 2018 01:47:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-patient-a-diagnosis-within-a-year-of-delivering-a-child-in/m-p/470836#M120508</guid>
      <dc:creator>jsimmo02</dc:creator>
      <dc:date>2018-06-17T01:47:50Z</dc:date>
    </item>
    <item>
      <title>Re: Find patient a diagnosis within a year of delivering a child in dataset where pt has multiple en</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-patient-a-diagnosis-within-a-year-of-delivering-a-child-in/m-p/470837#M120509</link>
      <description>&lt;P&gt;The hopeful output would be&lt;/P&gt;&lt;TABLE cellspacing="0" cellpadding="0" border="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Patient&lt;/TD&gt;&lt;TD&gt;Allconditionsmet&lt;/TD&gt;&lt;TD&gt;Year&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Patient x&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;TD&gt;2004&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Patient z&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;TD&gt;2001&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but if I can just create a flag for patients who meet all the criteria, I would be happy. Having the year return would be a bonus&lt;/P&gt;</description>
      <pubDate>Sun, 17 Jun 2018 01:47:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-patient-a-diagnosis-within-a-year-of-delivering-a-child-in/m-p/470837#M120509</guid>
      <dc:creator>jsimmo02</dc:creator>
      <dc:date>2018-06-17T01:47:03Z</dc:date>
    </item>
    <item>
      <title>Re: Find patient a diagnosis within a year of delivering a child in dataset where pt has multiple en</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-patient-a-diagnosis-within-a-year-of-delivering-a-child-in/m-p/470838#M120510</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Patient&amp;amp; $20.	Yearadmitted	SmokingFlag	DeliveryFlag ;
cards;
Patient x	2002	0	0
Patient x	2003	1	0
Patient x	2004	0	1
Patient x	2006	0	1
Patient x	2008	1	1
Patient y	2004	0	1
Patient z	2001	1	0
Patient z	2001	0	1
;
data want;
set have;
by patient;
retain t;
if first.patient then call missing(t);
if 	DeliveryFlag and t then if Yearadmitted-t in (0,1) then output;
if 	SmokingFlag=1 then t=Yearadmitted;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am not sure why you didn't include 2008 in your expected output though&lt;/P&gt;</description>
      <pubDate>Sun, 17 Jun 2018 02:17:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-patient-a-diagnosis-within-a-year-of-delivering-a-child-in/m-p/470838#M120510</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-06-17T02:17:19Z</dc:date>
    </item>
    <item>
      <title>Re: Find patient a diagnosis within a year of delivering a child in dataset where pt has multiple en</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-patient-a-diagnosis-within-a-year-of-delivering-a-child-in/m-p/470839#M120511</link>
      <description>&lt;P&gt;i should have&lt;/P&gt;</description>
      <pubDate>Sun, 17 Jun 2018 02:21:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-patient-a-diagnosis-within-a-year-of-delivering-a-child-in/m-p/470839#M120511</guid>
      <dc:creator>jsimmo02</dc:creator>
      <dc:date>2018-06-17T02:21:02Z</dc:date>
    </item>
    <item>
      <title>Re: Find patient a diagnosis within a year of delivering a child in dataset where pt has multiple en</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-patient-a-diagnosis-within-a-year-of-delivering-a-child-in/m-p/470840#M120512</link>
      <description>&lt;P&gt;Yes! YES! Nailed it&lt;/P&gt;</description>
      <pubDate>Sun, 17 Jun 2018 02:24:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-patient-a-diagnosis-within-a-year-of-delivering-a-child-in/m-p/470840#M120512</guid>
      <dc:creator>jsimmo02</dc:creator>
      <dc:date>2018-06-17T02:24:16Z</dc:date>
    </item>
    <item>
      <title>Re: Find patient a diagnosis within a year of delivering a child in dataset where pt has multiple en</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-patient-a-diagnosis-within-a-year-of-delivering-a-child-in/m-p/470841#M120513</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/85589"&gt;@jsimmo02&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Posting below even though things have moved on while I've been working out the code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's just another coding option for what you've got already.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines dlm='09'x truncover;
  input Patient $	Year_admitted	Smoking_Flag	Delivery_Flag;
datalines;
x	2002	0	0
x	2003	1	0
x	2004	0	1
x	2006	0	1
x	2008	1	1
y	2004	0	1
z	2001	1	0
z	2001	0	1
;
run;

data want;
  set have;
  by Patient notsorted Year_admitted;

  _r_sflg=lag(Smoking_Flag);

  if first.patient then return;
  
  /* also include delivery year for smoking flag */
  AllConditionsMet=  ( Delivery_Flag=1 and (Smoking_Flag=1 or _r_sflg=1) );

  if AllConditionsMet=1 then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 17 Jun 2018 02:39:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-patient-a-diagnosis-within-a-year-of-delivering-a-child-in/m-p/470841#M120513</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-06-17T02:39:53Z</dc:date>
    </item>
  </channel>
</rss>

