<?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: check if a character is an alphabet in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/check-if-a-character-is-an-alphabet/m-p/87574#M18738</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Toby, have you tested that PrxMatch code? When I use that one I'm getting zeroes where they shouldn't be.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 10 Aug 2012 01:50:08 GMT</pubDate>
    <dc:creator>GeoffreyBrent</dc:creator>
    <dc:date>2012-08-10T01:50:08Z</dc:date>
    <item>
      <title>check if a character is an alphabet</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-if-a-character-is-an-alphabet/m-p/87568#M18732</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Suppose I have one character variable with length = 1 and I want to check if the value is an alphabet only. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below is my code.Let me know if you have handier code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data t2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set&amp;nbsp; t1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if var1 in ("A","B","C","D", "E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y", "Z") then ind = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else ind = 0;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Aug 2012 17:29:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-if-a-character-is-an-alphabet/m-p/87568#M18732</guid>
      <dc:creator>kurofufu</dc:creator>
      <dc:date>2012-08-08T17:29:22Z</dc:date>
    </item>
    <item>
      <title>Re: check if a character is an alphabet</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-if-a-character-is-an-alphabet/m-p/87569#M18733</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Do you only want to check for uppercase characters?&amp;nbsp; Otherwise you could use:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data t2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set t1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; ind=anyalpha(var1);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if you really are only interested in upper case characters, you could use:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data t2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set t1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; ind=anyupper(var1);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Aug 2012 17:41:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-if-a-character-is-an-alphabet/m-p/87569#M18733</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-08-08T17:41:36Z</dc:date>
    </item>
    <item>
      <title>Re: check if a character is an alphabet</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-if-a-character-is-an-alphabet/m-p/87570#M18734</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data t1;&lt;BR /&gt;input var1 $;&lt;BR /&gt;cards;&lt;BR /&gt;a&lt;BR /&gt;b&lt;BR /&gt;2&lt;BR /&gt;5&lt;BR /&gt;t&lt;BR /&gt;r&lt;BR /&gt;;&lt;BR /&gt;data t2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set&amp;nbsp; t1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; ind=ifn(lengthn(compress(var1,,'ka'))=1,1,0);&lt;/P&gt;&lt;P&gt;run;&lt;BR /&gt;proc print;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Aug 2012 17:42:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-if-a-character-is-an-alphabet/m-p/87570#M18734</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2012-08-08T17:42:07Z</dc:date>
    </item>
    <item>
      <title>Re: check if a character is an alphabet</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-if-a-character-is-an-alphabet/m-p/87571#M18735</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Another option is using regular expressions:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data t2;&lt;/P&gt;&lt;P&gt;set t1;&lt;/P&gt;&lt;P&gt;one_alpha_rx=prxparse("/[a-zA-Z]/");&lt;/P&gt;&lt;P&gt;ind=prxmatch(one_alpha_rx,x);&lt;/P&gt;&lt;P&gt;drop one_alpha_rx;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For the problem you describe, you'd be better off using Art and Linlin's solutions - they're simpler and probably faster. But if you have to check more complex patterns some time, it's worth learning about regexp matching (this webform won't let me copy and paste, but there's a good paper on this in the SUGI29 archives).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As an example of where regexp comes in handy, I had an application where ID variables were expected to be twelve digits followed by an alpha character and then four more digits. To check whether inputs fit this rule, I used:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;legal_pattern=prxparse("/\d{12}[a-zA-Z]\d{4}/");&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note that regexp matching doesn't check whether the variable EXACTLY matches the pattern defined, only whether it appears somewhere in there. But this isn't a problem if the length of the regexp exactly matches the length of the variable.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Aug 2012 00:55:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-if-a-character-is-an-alphabet/m-p/87571#M18735</guid>
      <dc:creator>GeoffreyBrent</dc:creator>
      <dc:date>2012-08-09T00:55:37Z</dc:date>
    </item>
    <item>
      <title>Re: check if a character is an alphabet</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-if-a-character-is-an-alphabet/m-p/87572#M18736</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A similar question was asked about specifying an alphabetic range:&lt;/P&gt;&lt;P&gt;&lt;A _jive_internal="true" class="active_link" href="https://communities.sas.com/thread/35517"&gt;https://communities.sas.com/thread/35517&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HTH&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Aug 2012 12:24:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-if-a-character-is-an-alphabet/m-p/87572#M18736</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2012-08-09T12:24:25Z</dc:date>
    </item>
    <item>
      <title>Re: check if a character is an alphabet</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-if-a-character-is-an-alphabet/m-p/87573#M18737</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN class="j-status-levels"&gt; &lt;/SPAN&gt;&lt;SPAN class="j-post-author"&gt;&lt;STRONG&gt;&lt;A _jive_internal="true" class="jiveTT-hover-user jive-username-link" data-avatarid="-1" data-externalid="" data-presence="null" data-userid="808587" data-username="kurofufu" href="https://communities.sas.com/people/kurofufu" id="jive-80858745005787483226803"&gt;kurofufu&lt;/A&gt;,&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="j-post-author"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="j-post-author"&gt;&lt;STRONG&gt;Ind = AnyAlpha( Var1 ) ;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="j-post-author"&gt;&lt;STRONG&gt;Or&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="j-post-author"&gt;&lt;STRONG&gt;Ind = PrxMatch( '/a-z/o' , Var1 ) ;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="j-post-author"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="j-post-author"&gt;&lt;STRONG&gt;Either will do exactly what you want......&amp;nbsp; AnyAlpha will be slightly faster but isn't as portable given one has to know the translation table used for a specific set up...&amp;nbsp; &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Aug 2012 13:28:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-if-a-character-is-an-alphabet/m-p/87573#M18737</guid>
      <dc:creator>TobyDunn_hotmail_com</dc:creator>
      <dc:date>2012-08-09T13:28:01Z</dc:date>
    </item>
    <item>
      <title>Re: check if a character is an alphabet</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-if-a-character-is-an-alphabet/m-p/87574#M18738</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Toby, have you tested that PrxMatch code? When I use that one I'm getting zeroes where they shouldn't be.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Aug 2012 01:50:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-if-a-character-is-an-alphabet/m-p/87574#M18738</guid>
      <dc:creator>GeoffreyBrent</dc:creator>
      <dc:date>2012-08-10T01:50:08Z</dc:date>
    </item>
    <item>
      <title>Re: check if a character is an alphabet</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-if-a-character-is-an-alphabet/m-p/87575#M18739</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Geoffry,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Opps... I guess I shouldnt try to do too many things at the same time...the pattern modifier should have been a 'i' instead of 'o'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It should have been:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="j-post-author"&gt;Ind = PrxMatch( '/a-z/i' , Var1 ) ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="j-post-author"&gt;&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN class="j-post-author"&gt;This will match a-z and A-Z characters as the 'i' pattern modifier tells the RegEx engine to use case insensitivity.&amp;nbsp; There is no need for the 'o' pattern modifier since the pattern is explicitly and does not change.&amp;nbsp; Which means SAS by default will only compile it once.&amp;nbsp; Since Var1 is suppose to only be length of 1 the varibale does not need to be trimmed of any leading or trailing spaces.&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="j-post-author"&gt;&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN class="j-post-author"&gt;If one only wanted to check for lower case letters then:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="j-post-author"&gt;&lt;SPAN class="j-post-author"&gt;Ind = PrxMatch( '/a-z/' , Var1 ) ;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="j-post-author"&gt;&lt;SPAN class="j-post-author"&gt;&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN class="j-post-author"&gt;&lt;SPAN class="j-post-author"&gt;And for only upper case:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="j-post-author"&gt;&lt;SPAN class="j-post-author"&gt;&lt;SPAN class="j-post-author"&gt;Ind = PrxMatch( '/A-Z/' , Var1 ) ;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="j-post-author"&gt;&lt;SPAN class="j-post-author"&gt;&lt;SPAN class="j-post-author"&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN class="j-post-author"&gt;&lt;SPAN class="j-post-author"&gt;&lt;SPAN class="j-post-author"&gt;Sorry for the fat fingered and lack of proofing on the last post.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Aug 2012 14:51:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-if-a-character-is-an-alphabet/m-p/87575#M18739</guid>
      <dc:creator>TobyDunn_hotmail_com</dc:creator>
      <dc:date>2012-08-10T14:51:43Z</dc:date>
    </item>
  </channel>
</rss>

