<?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 exclude or identify patients who used two drugs on same day? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-exclude-or-identify-patients-who-used-two-drugs-on-same/m-p/800128#M314715</link>
    <description>&lt;P&gt;Why are you including #4 if it is not on the same day?&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 04 Mar 2022 13:07:32 GMT</pubDate>
    <dc:creator>tarheel13</dc:creator>
    <dc:date>2022-03-04T13:07:32Z</dc:date>
    <item>
      <title>How to exclude or identify patients who used two drugs on same day?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-exclude-or-identify-patients-who-used-two-drugs-on-same/m-p/800037#M314659</link>
      <description>&lt;P&gt;Hi, i am new to sas and handling the patients data right now, but having trouble excluding patients&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if i can use some of your help, i would be so grateful!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;here is the dataset i have&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID/converted_date(yymmdd10. format)/drug_name&lt;/P&gt;&lt;P&gt;1/2011-01-01/A&lt;/P&gt;&lt;P&gt;1/2011-01-01/B&lt;/P&gt;&lt;P&gt;1/2011-05-01/A&lt;/P&gt;&lt;P&gt;2/2012-03-07/A&lt;/P&gt;&lt;P&gt;2/2012-06-25/A&lt;/P&gt;&lt;P&gt;3/2013-01-12/A&lt;/P&gt;&lt;P&gt;3/2013-01-12/B&lt;/P&gt;&lt;P&gt;4/2014-01-12/B&lt;/P&gt;&lt;P&gt;4/2015-06-02/B&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this example i need to extract or get ID of patients #1, #3 and&amp;nbsp;&lt;/P&gt;&lt;P&gt;#2,#4 will be included in the table.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the dataset i have is about 50GB, so it is really heavy!!, it would be great if the code is simple and easy.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2022 02:29:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-exclude-or-identify-patients-who-used-two-drugs-on-same/m-p/800037#M314659</guid>
      <dc:creator>James_an</dc:creator>
      <dc:date>2022-03-04T02:29:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to exclude or identify patients who used two drugs on same day?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-exclude-or-identify-patients-who-used-two-drugs-on-same/m-p/800048#M314669</link>
      <description>&lt;P&gt;If it's the same drug on the same day, would you leave it?&lt;BR /&gt;I don't know if this two ways are correct since the results you want are not shown, but you can try.&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;/* one step */
proc sql;
  create table want1 as
    select a.* from have as a 
    left join have as b 
    on a.id=b.id and 
       a.converted_date=b.converted_date and
       a.drug_name^=b.drug_name
    where b.drug_name=''
;
quit;

/* two steps: sort and sql */
proc sort data=have  out=dup UNIQUEOUT=uniq NOUNIQUEKEY;
  by id converted_date;
run;
proc sql;
  create table want2 as
    select * from uniq 
  union all 
    select a.* from dup as a 
    left join dup as b 
    on a.id=b.id and 
       a.converted_date=b.converted_date and
       a.drug_name^=b.drug_name
    where b.drug_name=''
;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2022 03:28:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-exclude-or-identify-patients-who-used-two-drugs-on-same/m-p/800048#M314669</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2022-03-04T03:28:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to exclude or identify patients who used two drugs on same day?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-exclude-or-identify-patients-who-used-two-drugs-on-same/m-p/800117#M314707</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards dlm='/' truncover;
input id date :yymmdd10. drug $;
format date yymmdd10.;
cards;
1/2011-01-01/A
1/2011-01-01/B
1/2011-05-01/A
2/2012-03-07/A
2/2012-06-25/A
3/2013-01-12/A
3/2013-01-12/B
4/2014-01-12/B
4/2015-06-02/B
;

proc sql;
create table want as
select * from have 
 group by id
  having count(distinct drug)=2;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 04 Mar 2022 12:35:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-exclude-or-identify-patients-who-used-two-drugs-on-same/m-p/800117#M314707</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-03-04T12:35:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to exclude or identify patients who used two drugs on same day?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-exclude-or-identify-patients-who-used-two-drugs-on-same/m-p/800128#M314715</link>
      <description>&lt;P&gt;Why are you including #4 if it is not on the same day?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2022 13:07:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-exclude-or-identify-patients-who-used-two-drugs-on-same/m-p/800128#M314715</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2022-03-04T13:07:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to exclude or identify patients who used two drugs on same day?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-exclude-or-identify-patients-who-used-two-drugs-on-same/m-p/800166#M314730</link>
      <description>&lt;P&gt;So, what exactly to you want? Is the data sorted by patient and date?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=have noprint;
   table id*date / out=work.count(drop= percent where=(count &amp;gt; 1));
run;

proc sort data=work.count out=work.sorted nodupkey;
   by id;
run;

proc print;run;

data work.want;
   set work.have;
   
   if _n_ = 1 then do;
      declare hash h(dataset: 'work.sorted');
      h.defineKey('id');
      h.defineDone();
   end;
   
   if h.check() = 0 then delete; /* patient who used two drugs on same day are removed */   
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 04 Mar 2022 14:32:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-exclude-or-identify-patients-who-used-two-drugs-on-same/m-p/800166#M314730</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-03-04T14:32:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to exclude or identify patients who used two drugs on same day?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-exclude-or-identify-patients-who-used-two-drugs-on-same/m-p/800305#M314782</link>
      <description>&lt;P&gt;If&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;The data are sorted by ID/DATE&lt;/LI&gt;
&lt;LI&gt;No drug is issued twice in the same day for a given ID.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;then this program works;&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 id date;
  if not (first.date=1 and last.date=1);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The excludes all instances in which there is only one obs per date.&amp;nbsp; All the others must satisfy your condition.&lt;/P&gt;</description>
      <pubDate>Sat, 05 Mar 2022 05:10:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-exclude-or-identify-patients-who-used-two-drugs-on-same/m-p/800305#M314782</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-03-05T05:10:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to exclude or identify patients who used two drugs on same day?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-exclude-or-identify-patients-who-used-two-drugs-on-same/m-p/800326#M314797</link>
      <description>&lt;P&gt;because In case of #4, other drug was not prescribed on the same day! it will be remained!&lt;/P&gt;</description>
      <pubDate>Sat, 05 Mar 2022 11:06:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-exclude-or-identify-patients-who-used-two-drugs-on-same/m-p/800326#M314797</guid>
      <dc:creator>James_an</dc:creator>
      <dc:date>2022-03-05T11:06:44Z</dc:date>
    </item>
  </channel>
</rss>

