<?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 Patient_count based on cancer occurrence column in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Patient-count-based-on-cancer-occurrence-column/m-p/622166#M183008</link>
    <description>&lt;P&gt;Dear Experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I need a patient count for the condition based on the cancer occurrence. I'll share the sample dataset and the expected result for your reference.&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID Date mmddyy10. Inf Cancer;
cards;
123 05/05/2000 1 0
123 08/07/2001 0 1
123 06/07/2002 1 0
159 01/03/2001 1 1
159 02/08/2002 0 1
618 07/07/2005 0 0
618 05/03/2006 1 0
789 06/06/2000 1 0
789 04/02/2001 0 1
789 03/03/2002 1 0
789 03/03/2002 0 0
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I required 2 different outputs based on 2 conditions to get the patient IDs.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Patients who are Infected(Inf=1) after/same date on cancer (cancer=1) Expected Output(IDs 123,159,789).&lt;/LI&gt;&lt;LI&gt;Patients who are Infected(Inf=1) before cancer (cancer=1) Expected Output(IDs 123,789).&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Kindly suggests a code to get the patient IDs list at the end of the result.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note: The first occurrence of Cancer is matters but not the following occurrence.&lt;/P&gt;</description>
    <pubDate>Tue, 04 Feb 2020 12:11:13 GMT</pubDate>
    <dc:creator>Sathish_jammy</dc:creator>
    <dc:date>2020-02-04T12:11:13Z</dc:date>
    <item>
      <title>Patient_count based on cancer occurrence column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Patient-count-based-on-cancer-occurrence-column/m-p/622166#M183008</link>
      <description>&lt;P&gt;Dear Experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I need a patient count for the condition based on the cancer occurrence. I'll share the sample dataset and the expected result for your reference.&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID Date mmddyy10. Inf Cancer;
cards;
123 05/05/2000 1 0
123 08/07/2001 0 1
123 06/07/2002 1 0
159 01/03/2001 1 1
159 02/08/2002 0 1
618 07/07/2005 0 0
618 05/03/2006 1 0
789 06/06/2000 1 0
789 04/02/2001 0 1
789 03/03/2002 1 0
789 03/03/2002 0 0
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I required 2 different outputs based on 2 conditions to get the patient IDs.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Patients who are Infected(Inf=1) after/same date on cancer (cancer=1) Expected Output(IDs 123,159,789).&lt;/LI&gt;&lt;LI&gt;Patients who are Infected(Inf=1) before cancer (cancer=1) Expected Output(IDs 123,789).&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Kindly suggests a code to get the patient IDs list at the end of the result.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note: The first occurrence of Cancer is matters but not the following occurrence.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2020 12:11:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Patient-count-based-on-cancer-occurrence-column/m-p/622166#M183008</guid>
      <dc:creator>Sathish_jammy</dc:creator>
      <dc:date>2020-02-04T12:11:13Z</dc:date>
    </item>
    <item>
      <title>Re: Patient_count based on cancer occurrence column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Patient-count-based-on-cancer-occurrence-column/m-p/622169#M183009</link>
      <description>&lt;P&gt;This code gets your intended result, see if it also fits more complicated input data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID Date mmddyy10. Inf Cancer;
format date MMDDYY10.;
cards;
123 05/05/2000 1 0
123 08/07/2001 0 1
123 06/07/2002 1 0
159 01/03/2001 1 1
159 02/08/2002 0 1
618 07/07/2005 0 0
618 05/03/2006 1 0
789 06/06/2000 1 0
789 04/02/2001 0 1
789 03/03/2002 1 0
789 03/03/2002 0 0
;

proc sql;
create table after as
select distinct a.id
from
  have (where=(inf = 1)) a,
  (select id, min(date) as date from have (where=(cancer = 1)) group by id) b
where a.id = b.id and a.date &amp;gt;= b.date;
create table before as
select distinct a.id
from
  have (where=(inf = 1)) a,
  (select id, min(date) as date from have (where=(cancer = 1)) group by id) b
where a.id = b.id and a.date &amp;lt; b.date;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Feb 2020 12:24:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Patient-count-based-on-cancer-occurrence-column/m-p/622169#M183009</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-02-04T12:24:01Z</dc:date>
    </item>
    <item>
      <title>Re: Patient_count based on cancer occurrence column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Patient-count-based-on-cancer-occurrence-column/m-p/622170#M183010</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input ID Date mmddyy10. Inf Cancer;
format date mmddyy10.;
cards;
123 05/05/2000 1 0
123 08/07/2001 0 1
123 06/07/2002 1 0
159 01/03/2001 1 1
159 02/08/2002 0 1
618 07/07/2005 0 0
618 05/03/2006 1 0
789 06/06/2000 1 0
789 04/02/2001 0 1
789 03/03/2002 1 0
789 03/03/2002 0 0
;
proc sql;
/*Report 1 On/After*/
create table report1 as
select *
from have
group by id
having max(cancer=1);
/*Report 2 Before*/
create table report2 as
select *
from have
group by id
having min(ifn(inf=1,date,.)) &amp;lt; min(ifn(cancer=1,date,.)) ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Feb 2020 12:24:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Patient-count-based-on-cancer-occurrence-column/m-p/622170#M183010</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-02-04T12:24:56Z</dc:date>
    </item>
    <item>
      <title>Re: Patient_count based on cancer occurrence column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Patient-count-based-on-cancer-occurrence-column/m-p/622174#M183012</link>
      <description>&lt;P&gt;Since it appears your data is sorted by ID Date, Datastep seems a lot easier IMHO&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID Date mmddyy10. Inf Cancer;
format date mmddyy10.;
cards;
123 05/05/2000 1 0
123 08/07/2001 0 1
123 06/07/2002 1 0
159 01/03/2001 1 1
159 02/08/2002 0 1
618 07/07/2005 0 0
618 05/03/2006 1 0
789 06/06/2000 1 0
789 04/02/2001 0 1
789 03/03/2002 1 0
789 03/03/2002 0 0
;
data report1 report2;
 do _n_=1 by 1 until(last.id);
  set have;
  by id;
  if nmiss(_d,_d1)=0 then continue;
  if not _d1 and  Cancer=1 then _d1=date;
  if not _d and inf=1 then _d=date;
 end;
 do _n_=1 to _n_;
  set have;
  if _d1 then output report1;
  if _d&amp;lt;_d1 then output report2;
 end;
 drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Feb 2020 12:53:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Patient-count-based-on-cancer-occurrence-column/m-p/622174#M183012</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-02-04T12:53:44Z</dc:date>
    </item>
    <item>
      <title>Re: Patient_count based on cancer occurrence column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Patient-count-based-on-cancer-occurrence-column/m-p/622185#M183014</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Thank you for always stepping in to help when I need you most.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;it really meant a lot.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2020 13:59:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Patient-count-based-on-cancer-occurrence-column/m-p/622185#M183014</guid>
      <dc:creator>Sathish_jammy</dc:creator>
      <dc:date>2020-02-04T13:59:58Z</dc:date>
    </item>
  </channel>
</rss>

