Date: Fri, 12 Mar 2010 12:27:06 -0500
Reply-To: Toby Dunn <tobydunn@HOTMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Toby Dunn <tobydunn@HOTMAIL.COM>
Subject: Re: Check if a variable has any letter from A to Z. Is there a
function for it? Thanks
sarath,
While RegEx functions will work in this case I don't think they are
optimal. When a Prx function is used it has to be compile, then the
pattern and text are sent to the perl dll, have that do its job and send
the results back to SAS. This takes time. If there was a rule of thumb
and Im not saying there is, but if there was one, don't use Prx to do a
job that SAS already has a function for. In this case AnyAlpha was built
just for these types of problems. RegEx's are great for patterns that are
complicated or where SAS hasn't already built a function for.
Toby Dunn
On Fri, 12 Mar 2010 06:21:11 -0800, SAS programmer
<learnsasonline@GMAIL.COM> wrote:
>On Mar 10, 12:05 pm, Henry <chchanghe...@gmail.com> wrote:
>> Hi Alex,
>>
>> Thanks for your help!
>>
>> On Mar 10, 2:16 am, Alex <alexander.k...@iea-dpc.de> wrote:
>>
>>
>>
>> > On Mar 10, 5:33 am, Henry <chchanghe...@gmail.com> wrote:
>>
>> > > Hello there,
>>
>> > > I was wondering if there is a function that can help us to identify
if
>> > > there is a letter (no matter which one from A-Z) in a variable. Of
>> > > course the variable will be defined as character since it contains
>> > > some letters in some observations. So, just wonder if there is a
>> > > function to identify it as 0 or 1? In other words, can I get a new
>> > > indicator = 1 if the variable "answer" contains any letter from A to
>> > > Z. and = 0 if not containing any letter? Thanks a lot!
>>
>> > > DATA OLD;
>> > > INPUT ID $ 1-3
>> > > ANSWER $ 5-9;
>> > > DATALINES;
>> > > 001 ACBED
>> > > 002 11
>> > > 003 12
>> > > 004 zx
>> > > ;
>>
>> > Hi Henry,
>>
>> > Try out the anyalpha() function. It returns the first position at
>> > which a character is found in the string you pass to it. In your case
>> > you can use it like this in order to get a flag indicating whether
>> > ANSWER contains a letter or not:
>>
>> > DATA OLD;
>> > INPUT ID $ 1-3
>> > ANSWER $ 5-9;
>>
>> > ALPHA = ( anyalpha( ANSWER ) > 0 );
>>
>> > DATALINES;
>> > 001 ACBED
>> > 002 11
>> > 003 12
>> > 004 zx
>> > 005 1a
>> > ;
>> > run;
>> > proc print;
>> > run;
>>
>> > Note that I added record 005, which contains a letter at the 2nd
>> > position.
>>
>> > Cheers,
>> > Alex- Hide quoted text -
>>
>> - Show quoted text -
>
>Prxmatch () function is very useful in locating the matching strings.
>PRXMATCH () function returns the start position of the matching
>string.
>
>DATA OLD;
>INPUT ID $ 1-3 ANSWER $ 5-9;
>match=prxmatch("/[a-zA-Z]/",answer)>0;
>DATALINES;
>001 ACBED
>002 11
>003 12
>004 zx
>005 1a
>;
>run;
>proc print;
>run;
>
>sarath
>www.studysas.blogspot.com
|