<?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 Where clause multiple column with multiple values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Where-clause-multiple-column-with-multiple-values/m-p/527344#M143755</link>
    <description>&lt;DIV class="lia-message-body"&gt;&lt;DIV class="lia-message-body-content"&gt;&lt;P&gt;I am executing a query which has multiple columns in where clause which has multiple values. I know that in PROC SQL you can use IN condition to satisfy and get the correct output.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;FAKE DATA&lt;/P&gt;&lt;P&gt;Question: CHF is defined using the following diagnosis codes:&lt;BR /&gt;398.91, 402.11, 402.91, 404.11, 404.13, 404.91, 404.93 (Codes are in CHARATER form)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1.Query: (I merge two tables)&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table BENE_CHF as&lt;BR /&gt;select distinct a.BENE_ID, b.ICD9_DGNS_CD_1, ICD9_DGNS_CD_2, ICD9_DGNS_CD_3, ICD9_DGNS_CD_4, ICD9_DGNS_CD_5,ICD9_DGNS_CD_6, ICD9_DGNS_CD_7, ICD9_DGNS_CD_8,&lt;BR /&gt;LINE_ICD9_DGNS_CD_1,&lt;BR /&gt;LINE_ICD9_DGNS_CD_2,&lt;BR /&gt;LINE_ICD9_DGNS_CD_3,&lt;BR /&gt;LINE_ICD9_DGNS_CD_4,&lt;BR /&gt;LINE_ICD9_DGNS_CD_5,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; THIS QUERY IS WORKING&lt;BR /&gt;LINE_ICD9_DGNS_CD_6,&lt;BR /&gt;LINE_ICD9_DGNS_CD_7,&lt;BR /&gt;LINE_ICD9_DGNS_CD_8,&lt;BR /&gt;LINE_ICD9_DGNS_CD_9,&lt;BR /&gt;LINE_ICD9_DGNS_CD_10,&lt;BR /&gt;LINE_ICD9_DGNS_CD_11,&lt;BR /&gt;LINE_ICD9_DGNS_CD_12,&lt;BR /&gt;LINE_ICD9_DGNS_CD_13&lt;BR /&gt;from work.beneficiary_summary_file_2008 as a,&lt;BR /&gt;work.carrier_2008 as b&lt;BR /&gt;where a.BENE_ID = b.BENE_ID;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/***********************************************************************************************************/&lt;/P&gt;&lt;P&gt;Next sept is to sort the data according to ICD codes methioned above.&lt;/P&gt;&lt;P&gt;I tried different quries such as;&lt;/P&gt;&lt;P&gt;1.proc sql;&lt;BR /&gt;select *&lt;BR /&gt;from bene_chf&lt;BR /&gt;where ICD9_DGNS_CD_1 and&lt;BR /&gt;ICD9_DGNS_CD_2 and&lt;BR /&gt;ICD9_DGNS_CD_3 and&lt;BR /&gt;ICD9_DGNS_CD_4 and&lt;BR /&gt;ICD9_DGNS_CD_5 and&lt;BR /&gt;ICD9_DGNS_CD_6 and&lt;BR /&gt;ICD9_DGNS_CD_7 and&lt;BR /&gt;ICD9_DGNS_CD_8 and&lt;BR /&gt;LINE_ICD9_DGNS_CD_1 and&lt;BR /&gt;LINE_ICD9_DGNS_CD_2 and&lt;BR /&gt;LINE_ICD9_DGNS_CD_3 and&lt;BR /&gt;LINE_ICD9_DGNS_CD_4 and&lt;BR /&gt;LINE_ICD9_DGNS_CD_5 and&lt;BR /&gt;LINE_ICD9_DGNS_CD_6 and&lt;BR /&gt;LINE_ICD9_DGNS_CD_7 and&lt;BR /&gt;LINE_ICD9_DGNS_CD_8 and&lt;BR /&gt;LINE_ICD9_DGNS_CD_9 and&lt;BR /&gt;LINE_ICD9_DGNS_CD_10 and&lt;BR /&gt;LINE_ICD9_DGNS_CD_11 and&lt;BR /&gt;LINE_ICD9_DGNS_CD_12 and&lt;BR /&gt;LINE_ICD9_DGNS_CD_13 in ('39891', '40211', '40291', '40411', '40413', '40491', '40493', '42830');&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2.proc sql;&lt;BR /&gt;select *&lt;BR /&gt;from bene_chf&lt;BR /&gt;where ICD9_DGNS_CD_1&lt;BR /&gt;&amp;nbsp;in ('39891', '40211', '40291', '40411', '40413', '40491', '40493', '42830') or &amp;nbsp;&lt;BR /&gt;ICD9_DGNS_CD_2&lt;BR /&gt;in ('39891', '40211', '40291', '40411', '40413', '40491', '40493', '42830') or&lt;BR /&gt;ICD9_DGNS_CD_3&lt;BR /&gt;in ('39891', '40211', '40291', '40411', '40413', '40491', '40493', '42830') or&lt;BR /&gt;ICD9_DGNS_CD_4&lt;BR /&gt;in ('39891', '40211', '40291', '40411', '40413', '40491', '40493', '42830') or&lt;BR /&gt;ICD9_DGNS_CD_5&lt;BR /&gt;in ('39891', '40211', '40291', '40411', '40413', '40491', '40493', '42830')&lt;BR /&gt;group by bene_id;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Not able to get a right output.&lt;/P&gt;&lt;P&gt;any suggestion or comments are highly appriciated.&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Tue, 15 Jan 2019 15:40:46 GMT</pubDate>
    <dc:creator>prjadhav00</dc:creator>
    <dc:date>2019-01-15T15:40:46Z</dc:date>
    <item>
      <title>Where clause multiple column with multiple values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Where-clause-multiple-column-with-multiple-values/m-p/527344#M143755</link>
      <description>&lt;DIV class="lia-message-body"&gt;&lt;DIV class="lia-message-body-content"&gt;&lt;P&gt;I am executing a query which has multiple columns in where clause which has multiple values. I know that in PROC SQL you can use IN condition to satisfy and get the correct output.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;FAKE DATA&lt;/P&gt;&lt;P&gt;Question: CHF is defined using the following diagnosis codes:&lt;BR /&gt;398.91, 402.11, 402.91, 404.11, 404.13, 404.91, 404.93 (Codes are in CHARATER form)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1.Query: (I merge two tables)&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table BENE_CHF as&lt;BR /&gt;select distinct a.BENE_ID, b.ICD9_DGNS_CD_1, ICD9_DGNS_CD_2, ICD9_DGNS_CD_3, ICD9_DGNS_CD_4, ICD9_DGNS_CD_5,ICD9_DGNS_CD_6, ICD9_DGNS_CD_7, ICD9_DGNS_CD_8,&lt;BR /&gt;LINE_ICD9_DGNS_CD_1,&lt;BR /&gt;LINE_ICD9_DGNS_CD_2,&lt;BR /&gt;LINE_ICD9_DGNS_CD_3,&lt;BR /&gt;LINE_ICD9_DGNS_CD_4,&lt;BR /&gt;LINE_ICD9_DGNS_CD_5,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; THIS QUERY IS WORKING&lt;BR /&gt;LINE_ICD9_DGNS_CD_6,&lt;BR /&gt;LINE_ICD9_DGNS_CD_7,&lt;BR /&gt;LINE_ICD9_DGNS_CD_8,&lt;BR /&gt;LINE_ICD9_DGNS_CD_9,&lt;BR /&gt;LINE_ICD9_DGNS_CD_10,&lt;BR /&gt;LINE_ICD9_DGNS_CD_11,&lt;BR /&gt;LINE_ICD9_DGNS_CD_12,&lt;BR /&gt;LINE_ICD9_DGNS_CD_13&lt;BR /&gt;from work.beneficiary_summary_file_2008 as a,&lt;BR /&gt;work.carrier_2008 as b&lt;BR /&gt;where a.BENE_ID = b.BENE_ID;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/***********************************************************************************************************/&lt;/P&gt;&lt;P&gt;Next sept is to sort the data according to ICD codes methioned above.&lt;/P&gt;&lt;P&gt;I tried different quries such as;&lt;/P&gt;&lt;P&gt;1.proc sql;&lt;BR /&gt;select *&lt;BR /&gt;from bene_chf&lt;BR /&gt;where ICD9_DGNS_CD_1 and&lt;BR /&gt;ICD9_DGNS_CD_2 and&lt;BR /&gt;ICD9_DGNS_CD_3 and&lt;BR /&gt;ICD9_DGNS_CD_4 and&lt;BR /&gt;ICD9_DGNS_CD_5 and&lt;BR /&gt;ICD9_DGNS_CD_6 and&lt;BR /&gt;ICD9_DGNS_CD_7 and&lt;BR /&gt;ICD9_DGNS_CD_8 and&lt;BR /&gt;LINE_ICD9_DGNS_CD_1 and&lt;BR /&gt;LINE_ICD9_DGNS_CD_2 and&lt;BR /&gt;LINE_ICD9_DGNS_CD_3 and&lt;BR /&gt;LINE_ICD9_DGNS_CD_4 and&lt;BR /&gt;LINE_ICD9_DGNS_CD_5 and&lt;BR /&gt;LINE_ICD9_DGNS_CD_6 and&lt;BR /&gt;LINE_ICD9_DGNS_CD_7 and&lt;BR /&gt;LINE_ICD9_DGNS_CD_8 and&lt;BR /&gt;LINE_ICD9_DGNS_CD_9 and&lt;BR /&gt;LINE_ICD9_DGNS_CD_10 and&lt;BR /&gt;LINE_ICD9_DGNS_CD_11 and&lt;BR /&gt;LINE_ICD9_DGNS_CD_12 and&lt;BR /&gt;LINE_ICD9_DGNS_CD_13 in ('39891', '40211', '40291', '40411', '40413', '40491', '40493', '42830');&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2.proc sql;&lt;BR /&gt;select *&lt;BR /&gt;from bene_chf&lt;BR /&gt;where ICD9_DGNS_CD_1&lt;BR /&gt;&amp;nbsp;in ('39891', '40211', '40291', '40411', '40413', '40491', '40493', '42830') or &amp;nbsp;&lt;BR /&gt;ICD9_DGNS_CD_2&lt;BR /&gt;in ('39891', '40211', '40291', '40411', '40413', '40491', '40493', '42830') or&lt;BR /&gt;ICD9_DGNS_CD_3&lt;BR /&gt;in ('39891', '40211', '40291', '40411', '40413', '40491', '40493', '42830') or&lt;BR /&gt;ICD9_DGNS_CD_4&lt;BR /&gt;in ('39891', '40211', '40291', '40411', '40413', '40491', '40493', '42830') or&lt;BR /&gt;ICD9_DGNS_CD_5&lt;BR /&gt;in ('39891', '40211', '40291', '40411', '40413', '40491', '40493', '42830')&lt;BR /&gt;group by bene_id;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Not able to get a right output.&lt;/P&gt;&lt;P&gt;any suggestion or comments are highly appriciated.&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 15 Jan 2019 15:40:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Where-clause-multiple-column-with-multiple-values/m-p/527344#M143755</guid>
      <dc:creator>prjadhav00</dc:creator>
      <dc:date>2019-01-15T15:40:46Z</dc:date>
    </item>
    <item>
      <title>Re: Where clause multiple column with multiple values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Where-clause-multiple-column-with-multiple-values/m-p/527359#M143759</link>
      <description>&lt;P&gt;Provide a small example data set in the form of data step code and&amp;nbsp;expected outcome using that example data&amp;nbsp;for&lt;/P&gt;
&lt;PRE&gt;proc sql;
select *
from bene_chf
where ICD9_DGNS_CD_1
 in ('39891', '40211', '40291', '40411', '40413', '40491', '40493', '42830') or  
ICD9_DGNS_CD_2
in ('39891', '40211', '40291', '40411', '40413', '40491', '40493', '42830') or
ICD9_DGNS_CD_3
in ('39891', '40211', '40291', '40411', '40413', '40491', '40493', '42830') or
ICD9_DGNS_CD_4
in ('39891', '40211', '40291', '40411', '40413', '40491', '40493', '42830') or
ICD9_DGNS_CD_5
in ('39891', '40211', '40291', '40411', '40413', '40491', '40493', '42830')
group by bene_id;
quit;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Likely you could also reduce the number of variables to 2 or 3 and the list of values to 2 or 3 as well as long as the data and code behave the same.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One might also ask why you say&lt;/P&gt;
&lt;PRE&gt;CHF is defined using the following diagnosis codes:
398.91, 402.11, 402.91, 404.11, 404.13, 404.91, 404.93 (Codes are in CHARATER form)&lt;/PRE&gt;
&lt;P&gt;and then go to reference &amp;nbsp;('39891', '40211', '40291', '40411', '40413', '40491', '40493', '42830') &lt;STRONG&gt;without&lt;/STRONG&gt; the decimal. I'm not intimate with all of the ICD codes but I do believe it is possible to remove decimals and create duplicate results from different starts.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Suppose you have one code of 39.891 as well as 398.91. Removing decimals would yield 39891 for both.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jan 2019 16:16:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Where-clause-multiple-column-with-multiple-values/m-p/527359#M143759</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-01-15T16:16:36Z</dc:date>
    </item>
    <item>
      <title>Re: Where clause multiple column with multiple values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Where-clause-multiple-column-with-multiple-values/m-p/527367#M143764</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your first query has no values defined to multiple variables, then they will&amp;nbsp;take all the values (acts as not missing).&lt;/P&gt;
&lt;P&gt;Check this example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
var='A';var1='A';output;
var='B';var1=' ';output;
var=' ';var1=' ';output;
var=' ';var1='A';output;
;
run;

proc sql ;
select * from have
where var and var1; /* This will filter no missing values */
quit;

proc sql ;
select * from have
where not var and not var1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your second query works only if the values for those variables are character and there are no leading and trailing blanks only. Use STRIP() function to remove leading and trailing blanks.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;where strip(ICD9_DGNS_CD_1)
 in ('39891', '40211', '40291', '40411', '40413', '40491', '40493', '42830') or  
ICD9_DGNS_CD_2
in ('39891', '40211', '40291', '40411', '40413', '40491', '40493', '42830') .......so on&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Use numeric values if they are stored as numeric values in your source.&lt;/P&gt;
&lt;PRE&gt;where ICD9_DGNS_CD_1
 in (39891, 40211, 40291, 40411, 40413, 40491, 40493, 42830) or  
ICD9_DGNS_CD_2
in (39891, 40211, 40291, 40411, 40413, 40491, 40493, 42830) ......so on&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jan 2019 16:43:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Where-clause-multiple-column-with-multiple-values/m-p/527367#M143764</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2019-01-15T16:43:28Z</dc:date>
    </item>
    <item>
      <title>Re: Where clause multiple column with multiple values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Where-clause-multiple-column-with-multiple-values/m-p/527404#M143772</link>
      <description>&lt;P&gt;Hi SuryKiran,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your suggestion. I you suggested I used 'STRIP()'&amp;nbsp; still I am not getting the right output. Variables are the character.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am look for an output which can give the selected values &amp;nbsp;&lt;/P&gt;&lt;PRE&gt;('39891', '40211', '40291', '40411', '40413', '40491', '40493', '42830')&lt;/PRE&gt;&lt;P&gt;can you suggest me any other way.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jan 2019 17:36:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Where-clause-multiple-column-with-multiple-values/m-p/527404#M143772</guid>
      <dc:creator>prjadhav00</dc:creator>
      <dc:date>2019-01-15T17:36:34Z</dc:date>
    </item>
  </channel>
</rss>

