<?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: range of characters in PROC SQL where statement using LIKE operator? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/range-of-characters-in-PROC-SQL-where-statement-using-LIKE/m-p/244491#M56075</link>
    <description>I don't think this will work though. What if there are symbols like period or underscore, etc.&lt;BR /&gt;&lt;BR /&gt;In any case, I'm not specifically looking for solutions that has all alphabetic characters. That's just one example. I would want a solution that would work if I only wanted to search for string that contains any letter between say 'c' and 'k', etc.</description>
    <pubDate>Tue, 19 Jan 2016 17:16:05 GMT</pubDate>
    <dc:creator>CJ_Jackson</dc:creator>
    <dc:date>2016-01-19T17:16:05Z</dc:date>
    <item>
      <title>range of characters in PROC SQL where statement using LIKE operator?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/range-of-characters-in-PROC-SQL-where-statement-using-LIKE/m-p/244474#M56069</link>
      <description>&lt;P&gt;How do you select a range of characters in PROC SQL using the LIKE operator?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;DATA test;
	INPUT n x $;
	cards;
	1 abcd
	2 1000
	3 EF3H
	4 _4*4
	;
RUN;

PROC SQL;
	SELECT n, x
	FROM test
	WHERE x LIKE "%[A-Z]%"
	;
QUIT;&lt;/PRE&gt;&lt;P&gt;Row 3 should be selected, but when I run it no rows are selected.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;EDIT: my main goal is to select rows in which there are letters in the string. I get that you could do&lt;/P&gt;&lt;PRE&gt;if findc(lowcase(x),"abcdefghijklmnopqrstuvwxyz") &amp;gt; 0 &lt;/PRE&gt;&lt;P&gt;in a data step, but just wondering if there's an equivalent in PROC SQL since I'm already using it to query a SQL database. Also I would want a flexible way of doing something like this, so maybe I'm looking for strings where any character could be between A and L, or J and X etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2016 17:19:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/range-of-characters-in-PROC-SQL-where-statement-using-LIKE/m-p/244474#M56069</guid>
      <dc:creator>CJ_Jackson</dc:creator>
      <dc:date>2016-01-19T17:19:17Z</dc:date>
    </item>
    <item>
      <title>Re: range of characters in PROC SQL where statement using LIKE operator?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/range-of-characters-in-PROC-SQL-where-statement-using-LIKE/m-p/244476#M56070</link>
      <description>&lt;P&gt;You could use perl regular expressions. &amp;nbsp;I would use a small trick however. &amp;nbsp;Compress&amp;nbsp;function can remove certain sets of characters, then you can check the length:&lt;/P&gt;
&lt;PRE&gt;data test;
  input n x $;
cards;
1 abcd
2 1000
3 EFGH
4 efgh
;
run;

proc sql;
  create table WANT as
  select *
  from   TEST	&lt;BR /&gt;  where  lengthn(compress(X,' ','a'))=0;
quit;&lt;/PRE&gt;
&lt;P&gt;What I do is remove all the alphanumeric characters and blanks (blank from the second parameter, all characters with the 'a' option - check out the SAS docs for other options). &amp;nbsp;Then I take the length of the string and if it is zero then it only had those characters so we keep it. &amp;nbsp;Its basically reversing the thinking.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As a note, don't use tabs in your code, use 2 spaces, otherwise it renders differently in different editors.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2016 16:39:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/range-of-characters-in-PROC-SQL-where-statement-using-LIKE/m-p/244476#M56070</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-01-19T16:39:07Z</dc:date>
    </item>
    <item>
      <title>Re: range of characters in PROC SQL where statement using LIKE operator?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/range-of-characters-in-PROC-SQL-where-statement-using-LIKE/m-p/244479#M56071</link>
      <description>&lt;P&gt;As long as&amp;nbsp; you intend to examine the beginning of a character string, there is no need to use LIKE.&amp;nbsp; You can take advantage of the fact that there are no characters between "A" and "Z" in an ASCII collating sequence:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;where x &amp;gt;= 'A' and x &amp;lt; '[';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that "[" is the next character following "Z" in the ASCII collating sequence.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2016 16:48:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/range-of-characters-in-PROC-SQL-where-statement-using-LIKE/m-p/244479#M56071</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-01-19T16:48:45Z</dc:date>
    </item>
    <item>
      <title>Re: range of characters in PROC SQL where statement using LIKE operator?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/range-of-characters-in-PROC-SQL-where-statement-using-LIKE/m-p/244485#M56073</link>
      <description>&lt;P&gt;Ehh, tabs makes more sense since people like to see different indentation lengths. You could configure your editor to show however many spaces you like.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyway please see my edit. I'm trying to find rows in which the string has letter characters.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2016 17:02:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/range-of-characters-in-PROC-SQL-where-statement-using-LIKE/m-p/244485#M56073</guid>
      <dc:creator>CJ_Jackson</dc:creator>
      <dc:date>2016-01-19T17:02:40Z</dc:date>
    </item>
    <item>
      <title>Re: range of characters in PROC SQL where statement using LIKE operator?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/range-of-characters-in-PROC-SQL-where-statement-using-LIKE/m-p/244487#M56074</link>
      <description>&lt;P&gt;Update to my code to reflect your change in logic:&lt;/P&gt;
&lt;PRE&gt;data test;
  input n x $;
cards;
1 abcd
2 1000
3 EF3H
4 efgh
;
run;

proc sql;
  create table WANT as
  select *
  from   TEST
  where  lengthn(compress(X,' ','d')) &amp;gt;0;
quit;&lt;/PRE&gt;
&lt;P&gt;As for tabs, yes I could set my editors up to follow that logic, and change the setup of my browser to display them. &amp;nbsp;However I amnot going to do that as I would forever be changing setups. &amp;nbsp;Two spaces always render as two spaces, tabs render differently in every application, even posting your code above gives different results.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2016 17:07:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/range-of-characters-in-PROC-SQL-where-statement-using-LIKE/m-p/244487#M56074</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-01-19T17:07:47Z</dc:date>
    </item>
    <item>
      <title>Re: range of characters in PROC SQL where statement using LIKE operator?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/range-of-characters-in-PROC-SQL-where-statement-using-LIKE/m-p/244491#M56075</link>
      <description>I don't think this will work though. What if there are symbols like period or underscore, etc.&lt;BR /&gt;&lt;BR /&gt;In any case, I'm not specifically looking for solutions that has all alphabetic characters. That's just one example. I would want a solution that would work if I only wanted to search for string that contains any letter between say 'c' and 'k', etc.</description>
      <pubDate>Tue, 19 Jan 2016 17:16:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/range-of-characters-in-PROC-SQL-where-statement-using-LIKE/m-p/244491#M56075</guid>
      <dc:creator>CJ_Jackson</dc:creator>
      <dc:date>2016-01-19T17:16:05Z</dc:date>
    </item>
    <item>
      <title>Re: range of characters in PROC SQL where statement using LIKE operator?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/range-of-characters-in-PROC-SQL-where-statement-using-LIKE/m-p/244492#M56076</link>
      <description>Please see my edit. I'm not just searching for the first character, but in any character in the string where there's an alphabetic character.</description>
      <pubDate>Tue, 19 Jan 2016 17:18:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/range-of-characters-in-PROC-SQL-where-statement-using-LIKE/m-p/244492#M56076</guid>
      <dc:creator>CJ_Jackson</dc:creator>
      <dc:date>2016-01-19T17:18:05Z</dc:date>
    </item>
    <item>
      <title>Re: range of characters in PROC SQL where statement using LIKE operator?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/range-of-characters-in-PROC-SQL-where-statement-using-LIKE/m-p/244494#M56077</link>
      <description>&lt;P&gt;Ok, lets try this one then:&lt;/P&gt;
&lt;PRE&gt;data test;
  input n x $;
cards;
1 abcd
2 1000
3 EF3H
4 efgh
;
run;

proc sql;
  create table WANT as
  select *
  from   TEST
  where  findc(X,'a','a');
quit;&lt;/PRE&gt;
&lt;P&gt;Find will return the first position of a character given in the second parameter, and I use the 'a' third parameter to add all alphabet to the list.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2016 17:23:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/range-of-characters-in-PROC-SQL-where-statement-using-LIKE/m-p/244494#M56077</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-01-19T17:23:42Z</dc:date>
    </item>
    <item>
      <title>Re: range of characters in PROC SQL where statement using LIKE operator?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/range-of-characters-in-PROC-SQL-where-statement-using-LIKE/m-p/244499#M56078</link>
      <description>&lt;P&gt;I read your edit ... it seems like you are searching for any uppercase letter anywhere in the string, but ignoring lowercase letters.&amp;nbsp; If that's the case, this would be the key condition:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;where compress(x, , 'kU') &amp;gt; ' ';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Within the COMPRESS function, the third parameter is specifying k=KEEP rather than remove and U=Uppercase letters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to locate any letter (whether uppercase or lowercase) it would be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;where compress(x, , 'ka') &amp;gt; ' ';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of course, the SQL interpreter will need to understand how to use COMPRESS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And if you want a subset of the letters, you would still have to spell them out:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;where compress(x, 'ABCDEFGHIJ', 'k') &amp;gt; ' ';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2016 17:54:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/range-of-characters-in-PROC-SQL-where-statement-using-LIKE/m-p/244499#M56078</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-01-19T17:54:28Z</dc:date>
    </item>
  </channel>
</rss>

