<?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 PROC SQL: Multiple where statements in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Multiple-where-statements/m-p/727506#M226293</link>
    <description>&lt;P&gt;Hello Community,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to identify the number of patients in a dataset according to a set of conditions. First, I would like to identify the number of distinct patients who have received any prescription of a medication (medicationA) with a prescription start date prior to 9/1/2020 (start_date&amp;lt;'01SEP2020'd). This is specified via the variable "any" below. I would also like to identify the number of distinct patients who have received a non-injection formulation of medicationA with a prescription start date prior to 9/1/2020. This is specified via the variable "oral_med" in my code below. I am currently using the proc sql code below with multiple where conditions; however, this code is returning zero cases for both 'any' and 'oral_med', which is not true. Any suggestions on how to modify this code so that the conditions above can be properly obtained would be much appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select
	count(distinct patientID) as any,
	count(distinct case when route_medication not in ('Injection')
then patientID else . end) as oral_med
from have
where generic_name like 'medicationA' and start_date&amp;lt;'01SEP2020'd;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 18 Mar 2021 18:39:58 GMT</pubDate>
    <dc:creator>wj2</dc:creator>
    <dc:date>2021-03-18T18:39:58Z</dc:date>
    <item>
      <title>PROC SQL: Multiple where statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Multiple-where-statements/m-p/727506#M226293</link>
      <description>&lt;P&gt;Hello Community,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to identify the number of patients in a dataset according to a set of conditions. First, I would like to identify the number of distinct patients who have received any prescription of a medication (medicationA) with a prescription start date prior to 9/1/2020 (start_date&amp;lt;'01SEP2020'd). This is specified via the variable "any" below. I would also like to identify the number of distinct patients who have received a non-injection formulation of medicationA with a prescription start date prior to 9/1/2020. This is specified via the variable "oral_med" in my code below. I am currently using the proc sql code below with multiple where conditions; however, this code is returning zero cases for both 'any' and 'oral_med', which is not true. Any suggestions on how to modify this code so that the conditions above can be properly obtained would be much appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select
	count(distinct patientID) as any,
	count(distinct case when route_medication not in ('Injection')
then patientID else . end) as oral_med
from have
where generic_name like 'medicationA' and start_date&amp;lt;'01SEP2020'd;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 18:39:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Multiple-where-statements/m-p/727506#M226293</guid>
      <dc:creator>wj2</dc:creator>
      <dc:date>2021-03-18T18:39:58Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL: Multiple where statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Multiple-where-statements/m-p/727543#M226307</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/115194"&gt;@wj2&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code works on the test dataset HAVE created below&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
do patientID=1 to 8;
  do start_date='31AUG2020'd,'01SEP2020'd;
    do generic_name='medicationA','medicationB';
      do route_medication='Injection','Other';
        do _n_=1 to 3*ranuni(3);
          output;
        end;
      end;
    end;
  end;
end;
format start_date date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and the resulting WANT dataset&lt;/P&gt;
&lt;PRE&gt;Obs    any    oral_med

 1      7         4&lt;/PRE&gt;
&lt;P&gt;confirms the results of these PROC FREQ steps:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=have;
where generic_name='medicationA' &amp;amp; .z&amp;lt;start_date&amp;lt;'01SEP2020'd;
tables patientID;
run;

proc freq data=have;
where generic_name='medicationA' &amp;amp; .z&amp;lt;start_date&amp;lt;'01SEP2020'd &amp;amp; route_medication ne 'Injection';
tables patientID;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Therefore I suspect that the WHERE condition is not suitable for &lt;EM&gt;your&lt;/EM&gt; data (or vice versa). Possible reasons include case sensitivity, other spelling differences, invisible characters in the character variables, non-SAS date values (e.g. 1092020), etc. I would scrutinize one of the observations which should be selected, but aren't.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 19:50:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Multiple-where-statements/m-p/727543#M226307</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-03-18T19:50:47Z</dc:date>
    </item>
  </channel>
</rss>

