<?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: Filter on range of diagnosis codes that are strings in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Filter-on-range-of-diagnosis-codes-that-are-strings/m-p/751596#M236617</link>
    <description>&lt;P&gt;Thanks, something similar is my backup method. I would really like understand why my solution isn't working and how to fix it if possible.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 02 Jul 2021 00:09:42 GMT</pubDate>
    <dc:creator>kb011235</dc:creator>
    <dc:date>2021-07-02T00:09:42Z</dc:date>
    <item>
      <title>Filter on range of diagnosis codes that are strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filter-on-range-of-diagnosis-codes-that-are-strings/m-p/751583#M236608</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I was asked to find claims with diagnosis codes that are within a specific range, F320 to F339. The code I have almost works:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dx_start = F320 ; 
%let dx_end = F339 ; 

DATA dx_codes ;
	input diag $10. ;
	datalines ;
F22
F3010
F3013
F39
T1491XA
F320
F321
F322
F323
F324
F325
F330
F331
F332
F333
F3340
F3341
F3342
F338
F339
;
RUN ;

data want ;
  set dx_codes ;
	where "&amp;amp;dx_start." &amp;lt;=: diag &amp;lt;=: "&amp;amp;dx_end." ;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The output is below where the values in red shouldn't be included. Seems as if sas is checking if diag is 'like' or 'between' dx_start and dx_end.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;F320&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;F321&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;F322&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;F323&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;F324&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;F325&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;F330&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;F331&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;F332&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;F333&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#FF6600"&gt;F3340&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#FF6600"&gt;F3341&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#FF6600"&gt;F3342&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;F338&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;F339&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can my code be modified to check for exact matches?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jul 2021 22:08:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filter-on-range-of-diagnosis-codes-that-are-strings/m-p/751583#M236608</guid>
      <dc:creator>kb011235</dc:creator>
      <dc:date>2021-07-01T22:08:27Z</dc:date>
    </item>
    <item>
      <title>Re: Filter on range of diagnosis codes that are strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filter-on-range-of-diagnosis-codes-that-are-strings/m-p/751585#M236610</link>
      <description>&lt;P&gt;So the ones you want always begin with F, that have 3 numbers (not 2 numbers, not 4 numbers) and the numbers must be between 320 and 339? Is that correct?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set dx_codes ;
  number_part=input(substr(diag,2),6.);
  if 320&amp;lt;=number_part&amp;lt;=339 and diag=:'F';
  drop number_part;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want, you can replace the 320 and 339 with (modified) macro variables.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jul 2021 22:19:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filter-on-range-of-diagnosis-codes-that-are-strings/m-p/751585#M236610</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-07-01T22:19:08Z</dc:date>
    </item>
    <item>
      <title>Re: Filter on range of diagnosis codes that are strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filter-on-range-of-diagnosis-codes-that-are-strings/m-p/751596#M236617</link>
      <description>&lt;P&gt;Thanks, something similar is my backup method. I would really like understand why my solution isn't working and how to fix it if possible.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Jul 2021 00:09:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filter-on-range-of-diagnosis-codes-that-are-strings/m-p/751596#M236617</guid>
      <dc:creator>kb011235</dc:creator>
      <dc:date>2021-07-02T00:09:42Z</dc:date>
    </item>
    <item>
      <title>Re: Filter on range of diagnosis codes that are strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filter-on-range-of-diagnosis-codes-that-are-strings/m-p/751603#M236620</link>
      <description>&lt;P&gt;Your solution selects those extra records because of the colon in the comparisons:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;lt;=:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That means for comparison purposes, truncate the longer string down to the length of the shorter string.&amp;nbsp; So the comparisons are made on the basis of three characters (the length of the string in quotes).&amp;nbsp; Just get rid of the colons:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;lt;=&lt;/P&gt;</description>
      <pubDate>Fri, 02 Jul 2021 00:30:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filter-on-range-of-diagnosis-codes-that-are-strings/m-p/751603#M236620</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-07-02T00:30:00Z</dc:date>
    </item>
    <item>
      <title>Re: Filter on range of diagnosis codes that are strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filter-on-range-of-diagnosis-codes-that-are-strings/m-p/751606#M236621</link>
      <description>&lt;P&gt;I get the same results.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Jul 2021 00:58:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filter-on-range-of-diagnosis-codes-that-are-strings/m-p/751606#M236621</guid>
      <dc:creator>kb011235</dc:creator>
      <dc:date>2021-07-02T00:58:46Z</dc:date>
    </item>
    <item>
      <title>Re: Filter on range of diagnosis codes that are strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filter-on-range-of-diagnosis-codes-that-are-strings/m-p/751619#M236630</link>
      <description>&lt;P&gt;Try&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;where "&amp;amp;dx_start " &amp;lt;= DIAG&amp;lt;= "&amp;amp;dx_end " ;&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 02 Jul 2021 04:55:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filter-on-range-of-diagnosis-codes-that-are-strings/m-p/751619#M236630</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-07-02T04:55:59Z</dc:date>
    </item>
    <item>
      <title>Re: Filter on range of diagnosis codes that are strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filter-on-range-of-diagnosis-codes-that-are-strings/m-p/751779#M236710</link>
      <description>&lt;P&gt;Same results.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I found an explanation of why it's happening:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://support.sas.com/resources/papers/proceedings/proceedings/sugi26/p073-26.pdf" target="_blank" rel="noopener"&gt;https://support.sas.com/resources/papers/proceedings/proceedings/sugi26/p073-26.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;***********************************************************&lt;/P&gt;&lt;P&gt;In SAS, character strings must be adjusted to the same length&lt;BR /&gt;before they can be compared. When SAS compares character&lt;BR /&gt;strings without the colon modifier, it pads the shorter string with&lt;BR /&gt;blanks to the length of the longer string before making the&lt;BR /&gt;comparison. When SAS compares character strings with the&lt;BR /&gt;colon modifier after the operator, it truncates the longer string to&lt;BR /&gt;the length of the shorter string. This feature of the colon modifier&lt;BR /&gt;makes the comparison of a character string's prefix possible. For&lt;BR /&gt;example,&lt;BR /&gt;if zip='010' then do;&lt;BR /&gt;* This will pick up any zip which equals&lt;BR /&gt;'010' exactly;&lt;BR /&gt;if zip=:'010' then do;&lt;BR /&gt;* will pick up any zip starting with '010',&lt;BR /&gt;such as '01025','0103', '01098';&lt;BR /&gt;if zip&amp;gt;=:'010' then do;&lt;BR /&gt;* will pick up any zip from '010' up&lt;BR /&gt;alphabetically, such as '012', '21088';&lt;BR /&gt;where lastname gt: ‘Sm’;&lt;BR /&gt;* will pick up any last name alphabetically&lt;BR /&gt;higher than ‘Sm’, such as ‘Smith’,‘SNASH’,&lt;BR /&gt;‘Snash’;&lt;BR /&gt;The colon modifier can follow all comparison operators (=:, &amp;gt;=:,&lt;BR /&gt;&amp;lt;=:, ne:, gt:, lt:, in:) to conduct prefix comparison. The following&lt;BR /&gt;'in:' operation will select the students located in zip codes which&lt;BR /&gt;begin with '010', '011', '0131', '0138', respectively:&lt;BR /&gt;data s; set student;&lt;BR /&gt;if zip in:('010','011','0131','0138');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;**************************************&lt;/P&gt;&lt;P&gt;Seems like&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where "&amp;amp;dx_start." &amp;lt;= diag &amp;lt;= "&amp;amp;dx_end." ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;should work, but it doesn't.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Jul 2021 19:56:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filter-on-range-of-diagnosis-codes-that-are-strings/m-p/751779#M236710</guid>
      <dc:creator>kb011235</dc:creator>
      <dc:date>2021-07-02T19:56:58Z</dc:date>
    </item>
  </channel>
</rss>

