<?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: Filtering on multiple values with wildcards in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Filtering-on-multiple-values-with-wildcards/m-p/889061#M351229</link>
    <description>&lt;P&gt;Thanks! The problem with this approach is that the ICD10 list I have to match on is not always consistent in the characters that are present within it. E.g., There is a code Z87891, but then there are many codes like F23, F0633, E40. So it is all over the place, and I need to make sure that the existing table is filtered with the exact NDC value within this reference sheet I have.&lt;/P&gt;</description>
    <pubDate>Sat, 12 Aug 2023 21:16:14 GMT</pubDate>
    <dc:creator>shivenb</dc:creator>
    <dc:date>2023-08-12T21:16:14Z</dc:date>
    <item>
      <title>Filtering on multiple values with wildcards</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filtering-on-multiple-values-with-wildcards/m-p/888484#M351028</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am trying to create a new dataset (let's call it new_table) from an old dataset (called old_table) where the diagnosis variable (dx1) is equal to one of 150 diagnosis codes I have. Problem is that many of these diagnosis codes are broad with any value accepted beyond the first 3 specified letters. for example, for epilepsy, G40.xx where xx could represent any set of letters. I tried 2 ways of achieving this and both have failed. Any tweaks to either method or a totally new method would be appreciated!&lt;/P&gt;&lt;P&gt;Approach 1: Use wildcards within macro lists.&lt;/P&gt;&lt;P&gt;I have all these diagnosis values readily available where I can easily code them all by condition and combine them into a general macro list.&lt;/P&gt;&lt;P&gt;E.g. %let epilepsy = 'G40%', 'R56%'; %let nausea = 'R11%';&lt;/P&gt;&lt;P&gt;let% allicd10s = &amp;amp;epilepsy &amp;amp;nausea;&lt;/P&gt;&lt;P&gt;Then, I thought of using proc sql to get my new table&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table new_table as&lt;/P&gt;&lt;P&gt;select*&lt;/P&gt;&lt;P&gt;from old_table&lt;/P&gt;&lt;P&gt;where dx1 in (&amp;amp;allicd10s.);&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;This approach did not work because proc sql cannot read wild card function within macro lists.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Approach 2: use contains&lt;/P&gt;&lt;P&gt;I created a new table with all of the available diagnosis values. I named the table pci and named the variable icd10 and then used proc sql again&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table new_table as&lt;/P&gt;&lt;P&gt;select*&lt;/P&gt;&lt;P&gt;from old_table&lt;/P&gt;&lt;P&gt;where dx1 contains (select icd10 from pci);&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;Problem is that contains can only be used for a single string, which sounds quite a pointless feature. Are there any non-macro statement ways for me to use contains with an or function?&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am looking for a simpler solution than a macro statement only because I intend to use this for multiple variables in many ways (creating tables, creating other variables, summary counts, etc.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is appreciated!&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2023 23:03:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filtering-on-multiple-values-with-wildcards/m-p/888484#M351028</guid>
      <dc:creator>shivenb</dc:creator>
      <dc:date>2023-08-08T23:03:22Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering on multiple values with wildcards</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filtering-on-multiple-values-with-wildcards/m-p/888493#M351032</link>
      <description>&lt;P&gt;Does below solve your problem?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set sashelp.class;
  if name in: ('Ja','Ro');
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1691545315120.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/86554iA72339A41F033C95/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1691545315120.png" alt="Patrick_0-1691545315120.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alternatively a RegEx would work as well.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set sashelp.class;
  if prxmatch('/^(ja|ro)/oi',strip(name))&amp;gt;0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 Aug 2023 01:44:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filtering-on-multiple-values-with-wildcards/m-p/888493#M351032</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-08-09T01:44:15Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering on multiple values with wildcards</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filtering-on-multiple-values-with-wildcards/m-p/888504#M351035</link>
      <description>&lt;P&gt;Approach 3) test if the value is IN a list of desired values.&lt;/P&gt;
&lt;P&gt;In this case extract the first 3 characters (the vast majority of ICD10 codes before the decimal when present). This where would work in SQL as well&lt;/P&gt;
&lt;PRE&gt;data example;
   input code $;
datalines;
G40.23
A40.bc
C18.1
R56.99
A56.9
R56
B11
Q11.89
R11
;

data want;
  set example;
  where substr(code,1,3) in ('G40' 'R56' 'R11');
run;&lt;/PRE&gt;
&lt;P&gt;Another approach &lt;STRONG&gt;if&lt;/STRONG&gt; your shop has a complete enough custom format (or possibly formats) for ICD-10 codes is to use the Formatted value in a comparison.&lt;/P&gt;
&lt;P&gt;Dummy to show what that might look like:&lt;/P&gt;
&lt;PRE&gt;data dummy;
   set have;
   where put(dx1,$mycustomformat.) in ('Nausea' 'Epilepsy');
run;&lt;/PRE&gt;
&lt;P&gt;But not many shops have complete formats and you would need to use your format name(s) and the formatted values created by them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Aug 2023 06:16:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filtering-on-multiple-values-with-wildcards/m-p/888504#M351035</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-08-09T06:16:42Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering on multiple values with wildcards</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filtering-on-multiple-values-with-wildcards/m-p/889060#M351228</link>
      <description>&lt;P&gt;Thanks for your feedback! I tried this approach with a macro, and I am surprised that not only did it work, but I think it works more accurately than the weird solution I came up with. I tried the following approach and it ended up giving me a smaller resulting sample size. I cannot figure out how the following code and your code give a different result because my code is just getting at if there is at least 1 ICD10 value where the category&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;your suggested code restated in this context:&lt;/P&gt;&lt;P&gt;%let icd10 = 'F10', 'Z7141', 'K70', 'D50', 'D51', 'D52', 'D53', 'D55', 'D56', 'D57', .....;&lt;/P&gt;&lt;P&gt;data op_fac_icd10_a1;&lt;/P&gt;&lt;P&gt;set op_fac_a1;&lt;/P&gt;&lt;P&gt;if dx1 in: (&amp;amp;icd10.) or&amp;nbsp;dx2 in: (&amp;amp;icd10.) or&amp;nbsp;dx3 in: (&amp;amp;icd10.) or&amp;nbsp;dx4 in: (&amp;amp;icd10.) or&amp;nbsp;dx5 in: (&amp;amp;icd10.);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the code I ended up using is listed below where I ended up referencing ICD10 values in a variable in a table called pedcomindex:&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table op_fac_icd10_a1 as&lt;/P&gt;&lt;P&gt;select* from op_fac_a1 where (&lt;/P&gt;&lt;P&gt;exists (select 1 from pedcomindex where dx1 like '%'||icd10||'%')&lt;/P&gt;&lt;P&gt;or exists (select 1 from pedcomindex where dx2 like '%'||icd10||'%')&lt;/P&gt;&lt;P&gt;or exists (select 1 from pedcomindex where dx3 like '%'||icd10||'%')&lt;/P&gt;&lt;P&gt;or exists (select 1 from pedcomindex where dx4 like '%'||icd10||'%')&lt;/P&gt;&lt;P&gt;or exists (select 1 from pedcomindex where dx5 like '%'||icd10||'%')&lt;/P&gt;&lt;P&gt;);&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any thoughts? Thanks so much again for your response!&lt;/P&gt;</description>
      <pubDate>Sat, 12 Aug 2023 21:13:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filtering-on-multiple-values-with-wildcards/m-p/889060#M351228</guid>
      <dc:creator>shivenb</dc:creator>
      <dc:date>2023-08-12T21:13:39Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering on multiple values with wildcards</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filtering-on-multiple-values-with-wildcards/m-p/889061#M351229</link>
      <description>&lt;P&gt;Thanks! The problem with this approach is that the ICD10 list I have to match on is not always consistent in the characters that are present within it. E.g., There is a code Z87891, but then there are many codes like F23, F0633, E40. So it is all over the place, and I need to make sure that the existing table is filtered with the exact NDC value within this reference sheet I have.&lt;/P&gt;</description>
      <pubDate>Sat, 12 Aug 2023 21:16:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filtering-on-multiple-values-with-wildcards/m-p/889061#M351229</guid>
      <dc:creator>shivenb</dc:creator>
      <dc:date>2023-08-12T21:16:14Z</dc:date>
    </item>
  </channel>
</rss>

