<?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 Specifying character ranges in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Specifying-character-ranges/m-p/306437#M61014</link>
    <description>&lt;P&gt;Is there an easier way to specify a range when your variable is a character?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, I am recoding a bunch of revenue/procedure codes into categories, but using the IN() function doesn't work well for ranges that are not numeric. &amp;nbsp;So I would like to do this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;if c_dtl_proc_cd in (59000:59899, 90801:90899, A4651:A4932) then category='2. Other';&lt;/PRE&gt;&lt;P&gt;But this doesn't seem to work. &amp;nbsp;It seems like I would have to do this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;if (c_dtl_proc_cd ge '59000' and c_dtl_proc_cd le '59899') or
(c_dtl_proc_cd ge '90935' and c_dtl_proc_cd le '90899') or
(c_dtl_proc_cd ge 'A4651' and c_dtl_proc_cd le 'A4932')  then 
	category='2. Other';&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Which wouldn't be too bad, except that some of the categories have a series of different ranges.&lt;/P&gt;&lt;P&gt;Is there an easier way to list these ranges?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Fri, 21 Oct 2016 20:23:09 GMT</pubDate>
    <dc:creator>einstein</dc:creator>
    <dc:date>2016-10-21T20:23:09Z</dc:date>
    <item>
      <title>Specifying character ranges</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Specifying-character-ranges/m-p/306437#M61014</link>
      <description>&lt;P&gt;Is there an easier way to specify a range when your variable is a character?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, I am recoding a bunch of revenue/procedure codes into categories, but using the IN() function doesn't work well for ranges that are not numeric. &amp;nbsp;So I would like to do this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;if c_dtl_proc_cd in (59000:59899, 90801:90899, A4651:A4932) then category='2. Other';&lt;/PRE&gt;&lt;P&gt;But this doesn't seem to work. &amp;nbsp;It seems like I would have to do this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;if (c_dtl_proc_cd ge '59000' and c_dtl_proc_cd le '59899') or
(c_dtl_proc_cd ge '90935' and c_dtl_proc_cd le '90899') or
(c_dtl_proc_cd ge 'A4651' and c_dtl_proc_cd le 'A4932')  then 
	category='2. Other';&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Which wouldn't be too bad, except that some of the categories have a series of different ranges.&lt;/P&gt;&lt;P&gt;Is there an easier way to list these ranges?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2016 20:23:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Specifying-character-ranges/m-p/306437#M61014</guid>
      <dc:creator>einstein</dc:creator>
      <dc:date>2016-10-21T20:23:09Z</dc:date>
    </item>
    <item>
      <title>Re: Specifying character ranges</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Specifying-character-ranges/m-p/306439#M61015</link>
      <description>&lt;P&gt;Not easily. Can you do a format instead?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it's character but actually a number&amp;nbsp;you can convert it to numeric to check ranges?&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2016 20:29:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Specifying-character-ranges/m-p/306439#M61015</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-10-21T20:29:00Z</dc:date>
    </item>
    <item>
      <title>Re: Specifying character ranges</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Specifying-character-ranges/m-p/306441#M61017</link>
      <description>&lt;P&gt;I need to look at combinations of these categories within a visit, so I don't think a format would work well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Converting it to numeric would work except that they're not all numbers, so that wouldn't work.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2016 20:37:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Specifying-character-ranges/m-p/306441#M61017</guid>
      <dc:creator>einstein</dc:creator>
      <dc:date>2016-10-21T20:37:00Z</dc:date>
    </item>
    <item>
      <title>Re: Specifying character ranges</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Specifying-character-ranges/m-p/306444#M61018</link>
      <description>&lt;P&gt;In general, it appears to be a look up. You recode from one value to another. Not sure how a format wouldn't work here...&lt;/P&gt;
&lt;P&gt;Perhaps post more sample data and expected output. Do you have your rules for recoding in a data table anywhere? Or do they exist in your head?&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2016 20:39:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Specifying-character-ranges/m-p/306444#M61018</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-10-21T20:39:31Z</dc:date>
    </item>
    <item>
      <title>Re: Specifying character ranges</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Specifying-character-ranges/m-p/306445#M61019</link>
      <description>&lt;P&gt;These are claims, so I have multiple lines for a single visit. &amp;nbsp;I think it&amp;nbsp;would be much easier to create a bunch of flags to see what is happening during a visit. &amp;nbsp;I don't see how a format would work in this instance.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2016 20:44:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Specifying-character-ranges/m-p/306445#M61019</guid>
      <dc:creator>einstein</dc:creator>
      <dc:date>2016-10-21T20:44:50Z</dc:date>
    </item>
    <item>
      <title>Re: Specifying character ranges</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Specifying-character-ranges/m-p/306450#M61020</link>
      <description>&lt;P&gt;It's probably a bit of personal preference but I really find formats for recoding much easier to manage than multiple if then statements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data format;
fmtname = "awesome_fmt";
type="C";
do value=59000 to 59899, 90935 to 90899;
start=put(value, $8.);
label='Other';
output;
end;

do value=4651 to 4932;
start=catt("A", value);
label='Other';
output;
end;

run;

proc format cntlin=format;
run;

data test;
set my_data;

category=put(c_dtl_proc_cd, $awesome_fmt.);

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 Oct 2016 20:57:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Specifying-character-ranges/m-p/306450#M61020</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-10-21T20:57:05Z</dc:date>
    </item>
    <item>
      <title>Re: Specifying character ranges</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Specifying-character-ranges/m-p/306455#M61021</link>
      <description>&lt;P&gt;Before you do this, you have to consider that garbage values will be included in character ranges. &amp;nbsp;For example, you have a character range:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"A4561" - "A4932"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As character strings, this range includes these values:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"A46.1"&lt;/P&gt;
&lt;P&gt;"A47CD"&lt;/P&gt;
&lt;P&gt;"A49"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is your data clean enough to support a switch to ranges?&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2016 21:32:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Specifying-character-ranges/m-p/306455#M61021</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-10-21T21:32:26Z</dc:date>
    </item>
    <item>
      <title>Re: Specifying character ranges</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Specifying-character-ranges/m-p/306833#M61060</link>
      <description>&lt;P&gt;Yes, i agree it is sometimes personal preference, but you're right, this is probably cleaner and works just as well! &amp;nbsp;Thanks so much!&lt;/P&gt;</description>
      <pubDate>Mon, 24 Oct 2016 15:00:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Specifying-character-ranges/m-p/306833#M61060</guid>
      <dc:creator>einstein</dc:creator>
      <dc:date>2016-10-24T15:00:20Z</dc:date>
    </item>
    <item>
      <title>Re: Specifying character ranges</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Specifying-character-ranges/m-p/306836#M61061</link>
      <description>&lt;P&gt;Excellent point! Yes, &amp;nbsp;luckily my values are clean, so I won't have to worry about garbage&amp;nbsp;in the ranges.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 24 Oct 2016 15:01:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Specifying-character-ranges/m-p/306836#M61061</guid>
      <dc:creator>einstein</dc:creator>
      <dc:date>2016-10-24T15:01:28Z</dc:date>
    </item>
  </channel>
</rss>

