<?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 Flagging based on two criteria within specific period in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Flagging-based-on-two-criteria-within-specific-period/m-p/501061#M133550</link>
    <description>&lt;P&gt;&lt;STRONG&gt;DATA&lt;/STRONG&gt; HAVE;&lt;/P&gt;&lt;P&gt;INPUT patientid &lt;STRONG&gt;1-2&lt;/STRONG&gt; &lt;STRONG&gt;dx1&lt;/STRONG&gt; &lt;STRONG&gt;3-5&lt;/STRONG&gt; &lt;STRONG&gt;dx2&lt;/STRONG&gt; &lt;STRONG&gt;7-9&lt;/STRONG&gt; &lt;STRONG&gt;dx3&lt;/STRONG&gt; &lt;STRONG&gt;11-13&lt;/STRONG&gt; &lt;STRONG&gt;dx4&lt;/STRONG&gt; &lt;STRONG&gt;15-17&lt;/STRONG&gt; date mmddyy10.;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1 250 223 224 444 5/5/2009&lt;/P&gt;&lt;P&gt;1 555 666 120 290 10/6/2009&lt;/P&gt;&lt;P&gt;2 120 666 120 290 1/2/2007&lt;/P&gt;&lt;P&gt;2 120 666 120 290 1/1/2007&lt;/P&gt;&lt;P&gt;3 250 120 290 120 2/2/2004&lt;/P&gt;&lt;P&gt;3 240 250 120 290 3/3/2004&lt;/P&gt;&lt;P&gt;3 250 120 290 120 1/1/2004&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;I want to flag patients who meets the following conditions:&lt;/P&gt;&lt;P&gt;have two dx='666' occurring with one year&lt;/P&gt;&lt;P&gt;or those who have one dx='666' and one dx='250' within one year&lt;/P&gt;&lt;P&gt;The output for this example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1 250 223 224 444 5/5/2009 
1 555 666 120 290 10/6/2009 
2 120 666 1/2/2007 
2 120 666 1/1/2007&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 03 Oct 2018 10:13:53 GMT</pubDate>
    <dc:creator>lillymaginta</dc:creator>
    <dc:date>2018-10-03T10:13:53Z</dc:date>
    <item>
      <title>Flagging based on two criteria within specific period</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-based-on-two-criteria-within-specific-period/m-p/501061#M133550</link>
      <description>&lt;P&gt;&lt;STRONG&gt;DATA&lt;/STRONG&gt; HAVE;&lt;/P&gt;&lt;P&gt;INPUT patientid &lt;STRONG&gt;1-2&lt;/STRONG&gt; &lt;STRONG&gt;dx1&lt;/STRONG&gt; &lt;STRONG&gt;3-5&lt;/STRONG&gt; &lt;STRONG&gt;dx2&lt;/STRONG&gt; &lt;STRONG&gt;7-9&lt;/STRONG&gt; &lt;STRONG&gt;dx3&lt;/STRONG&gt; &lt;STRONG&gt;11-13&lt;/STRONG&gt; &lt;STRONG&gt;dx4&lt;/STRONG&gt; &lt;STRONG&gt;15-17&lt;/STRONG&gt; date mmddyy10.;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1 250 223 224 444 5/5/2009&lt;/P&gt;&lt;P&gt;1 555 666 120 290 10/6/2009&lt;/P&gt;&lt;P&gt;2 120 666 120 290 1/2/2007&lt;/P&gt;&lt;P&gt;2 120 666 120 290 1/1/2007&lt;/P&gt;&lt;P&gt;3 250 120 290 120 2/2/2004&lt;/P&gt;&lt;P&gt;3 240 250 120 290 3/3/2004&lt;/P&gt;&lt;P&gt;3 250 120 290 120 1/1/2004&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;I want to flag patients who meets the following conditions:&lt;/P&gt;&lt;P&gt;have two dx='666' occurring with one year&lt;/P&gt;&lt;P&gt;or those who have one dx='666' and one dx='250' within one year&lt;/P&gt;&lt;P&gt;The output for this example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1 250 223 224 444 5/5/2009 
1 555 666 120 290 10/6/2009 
2 120 666 1/2/2007 
2 120 666 1/1/2007&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Oct 2018 10:13:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-based-on-two-criteria-within-specific-period/m-p/501061#M133550</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2018-10-03T10:13:53Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging based on two criteria within specific period</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-based-on-two-criteria-within-specific-period/m-p/501066#M133551</link>
      <description>&lt;P&gt;Your test datastep does not work.&amp;nbsp; Therefore, just theory:&lt;/P&gt;
&lt;P&gt;Retain a variable across rows which is the sum condition, do this by patient id year period - another variable to create?&lt;/P&gt;
&lt;P&gt;If any of array dx is 666 or 250, then add one to sum condition.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If last.patientid and sum&amp;gt;=2 then output.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Oct 2018 10:04:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-based-on-two-criteria-within-specific-period/m-p/501066#M133551</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-10-03T10:04:03Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging based on two criteria within specific period</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-based-on-two-criteria-within-specific-period/m-p/501069#M133552</link>
      <description>&lt;P&gt;Thank you for the response, I corrected the data. I can flag the variables but I am not sure I fully understood how to differentiate between the two conditions in the code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;If variables a would flag 666&amp;nbsp;&lt;/P&gt;&lt;P&gt;and variable b flag 250&amp;nbsp;&lt;/P&gt;&lt;P&gt;the condition is that if a=1 and a=1 within a year then 1&lt;/P&gt;&lt;P&gt;or if a=1 and b=1 withing a year then 1&amp;nbsp;&lt;/P&gt;&lt;P&gt;However of b=1 and b=1 only (meaning no other a=1) within a year then 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Oct 2018 10:17:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-based-on-two-criteria-within-specific-period/m-p/501069#M133552</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2018-10-03T10:17:38Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging based on two criteria within specific period</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-based-on-two-criteria-within-specific-period/m-p/501075#M133554</link>
      <description>&lt;P&gt;Well, this works, its a bit verbose:&lt;/P&gt;
&lt;PRE&gt;data have;
  input patientid 1-2 dx1 3-5 dx2 7-9 dx3 11-13 dx4 15-17 date mmddyy10.;
datalines;
1 250 223 224 444 5/5/2009
1 555 666 120 290 10/6/2009
2 120 666 120 290 1/2/2007
2 120 666 120 290 1/1/2007
3 250 120 290 120 2/2/2004
3 240 250 120 290 3/3/2004
3 250 120 290 120 1/1/20042
;
run;
 
data inter;
  set have;
  by patientid;
  retain tmp1 tmp2;
  if first.patientid then do;
    tmp1=index(catx(",",of dx:),"666");
    tmp2=index(catx(",",of dx:),"250");
  end;
  if last.patientid and intck("year",lag(date),date) &amp;lt;= 1 then do;
    if tmp1 and index(catx(",",of dx:),"666") then output;
    if (tmp1 and index(catx(",",of dx:),"250")) or (tmp2 and index(catx(",",of dx:),"666")) then output;
  end;
run;

proc sql;
  create table want as
  select *
  from   have
  where patientid in (select patientid from inter);
quit;&lt;/PRE&gt;
&lt;P&gt;Could probably drop it to one step with a do while loop.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Oct 2018 10:55:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-based-on-two-criteria-within-specific-period/m-p/501075#M133554</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-10-03T10:55:40Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging based on two criteria within specific period</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-based-on-two-criteria-within-specific-period/m-p/501096#M133568</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input patientid 1-2 dx1 3-5 dx2 7-9 dx3 11-13 dx4 15-17 date mmddyy10.;
  year=year(date);
  format date mmddyy10.;
datalines;
1 250 223 224 444 5/5/2009
1 555 666 120 290 10/6/2009
2 120 666 120 290 1/2/2007
2 120 666 120 290 1/1/2007
3 250 120 290 120 2/2/2004
3 240 250 120 290 3/3/2004
3 250 120 290 120 1/1/20042
;
run;
 
proc sql;
  create table temp as
  select patientid,year,
  sum(dx1=666)+sum(dx2=666)+sum(dx3=666) as sum_666,
  sum(dx1=250)+sum(dx2=250)+sum(dx3=250) as sum_250
  from   have
  group by patientid,year
  having calculated sum_666=2 or (calculated sum_666=1 and calculated sum_250=1);

  create table want as
  select *
  from have
  where patientid in (select patientid from temp);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Oct 2018 11:53:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-based-on-two-criteria-within-specific-period/m-p/501096#M133568</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-10-03T11:53:46Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging based on two criteria within specific period</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-based-on-two-criteria-within-specific-period/m-p/501123#M133578</link>
      <description>&lt;P&gt;Thank you both!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Oct 2018 13:03:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-based-on-two-criteria-within-specific-period/m-p/501123#M133578</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2018-10-03T13:03:35Z</dc:date>
    </item>
  </channel>
</rss>

