LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (October 2000, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 18 Oct 2000 16:51:48 GMT
Reply-To:     Paul Dorfman <paul_dorfman@HOTMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Paul Dorfman <paul_dorfman@HOTMAIL.COM>
Subject:      Re: How to check if character data is all alpha?
Comments: To: dmclerra@FHCRC.ORG
Content-Type: text/plain; format=flowed

Dale,

You are rising a valid issue: There might be various definitions of what character or numeric string is. Your macro is, of course, most general. VERIFY is fine except that listing all the values considered 'character' as one of its arguments feels rather kludgy.

If the string contains 32 characters or less, standard SAS informats can be put to a good use for this purpose. For example, if the definition of the character string is that of a digital string - 'digits only', then the expression

(input(compress(str,'.'), ?? 32.) ne .)

evaluates to 1 if the string is all digits and to 0 if a non-digit byte is present. If the definition is such that 12333.234 is considered numeric, then

(input(str, ?? 32.) ne .)

does the same. If the definition is such that 12,333.234 is regarded as numeric,

(input(str, ?? comma32.) ne .)

will do the trick. It appears that along those lines, one can also make use of other existing informats for this purpose as well. For one, think about the DOLLAR. informat.

Kind regards, ======================= Paul M. Dorfman Jacksonville, Fl =======================

>From: Dale McLerran <dmclerra@FHCRC.ORG> >Reply-To: Dale McLerran <dmclerra@FHCRC.ORG> >To: SAS-L@LISTSERV.UGA.EDU >Subject: Re: How to check if character data is all alpha? >Date: Tue, 17 Oct 2000 17:46:55 GMT > >The issue of "What is alpha?" which Gerhard raises also troubles me. >More than likely, most of the symbols on the keypad should be >regarded as character. Making sure of the inclusion of all of the >proper symbols in the verify function seems a little difficult to >me. Also, the number and position of symbols may render a string >character. If we have more than one decimal point in the string, then >string is character (at least for us Americans). If there is a dollar >sign in any position other than the first position, then string is >character. Certainly, other rules could be generated. Let me >describe a method which I recently suggested to a colleague which, I >believe, is more rigorous for constructing the specification of what >is alpha and what is numeric. The approach is not the oneliner which >can be implemented with the verify function, so there is some tradeoff. > >I start by initializing an indicator variable to status numeric. I >then examine the string character by character to see if there is any >non-numeric element encountered. Non-numeric means any value outside >of the collating sequence from '0' through '9'. If a non-numeric >element is encountered, then the indicator variable is set to status >character and I terminate the do loop execution. At the end of the >do loop, my indicator variable can be used to determine what type of >action can be used on the string. > >str_int=1; >do i=1 to length(string); > if ^('0'<=substr(string,i,1)<='9') then do; > /* i-th character not in collating sequence between '0' and '9' */ > str_int=0; > leave; > end; >end; > >The above code determines whether STRING has an integer value. If >STRING has any characters other than those found in the collating >sequence between '0' and '9', then STRING is not integer. Now, >suppose that we would like to allow real numbers to constitute >a numeric value. Real numbers have digits which fall between '0' and >'9', along with possibly a decimal point. We could update our code >as follows: > >str_num=1; >ndec=0; /* keep counter of number of decimal points in string */ >do i=1 to length(string); > __char = substr(string,i,1); > if ^('0'<=__char<='9') then do; > /* i-th character not in collating sequence between '0' and '9' */ > if __char='.' then do; > /* i-th character is decimal point */ > ndec+1; > if ndec>1 then do; > /* If more than one decimal point, then not numeric */ > str_num=0; > leave; > end; > end; > else do; > /* i-th character not decimal and not in '0' through '9' */ > str_num=0; > leave; > end; > end; >end; > > >As I said, this is not the oneliner which the verify function offers. >However, I would be interested in folks reactions to code along >these lines. Is it necessary to be concerned about the symbols? >Does this line of programming make specification of data type more >rigorous? Are there improvements which could be made to the above >code which would make it a) more compact?, b) simpler to understand?, >c) more efficient? > >Dale > >-------------------------------------- >Dale McLerran >Fred Hutchinson Cancer Research Center >Seattle, WA 98109 >mailto:dmclerra@fhcrc.org >ph: (206) 667-2926 >fax: (206) 667-5977 >-------------------------------------- > >ghellrieg@T-ONLINE.DE (Gerhard Hellriegel) wrote in ><200010161633.e9GGXbl181216@listserv.cc.uga.edu>: > > >On Mon, 16 Oct 2000 16:19:49 GMT, Brian Shore <bgs50@HOTMAIL.COM> wrote: > > > >>Hi, > >> > >>Is there a way in SAS to determine if a character variable contains all > >>alphabetic data? For example, I read a var called ACCOUNT and I want > >>to know if the account number contains all alphabetic data. In some > >>languages (C, SQL?), there is a function called ISALPHA() that does > >>this, but I don't know of any such function in SAS. > >> > >>thanks > >>________________________________________________________________________ > >>_ Get Your Private, Free E-mail from MSN Hotmail at > >>http://www.hotmail.com. > >> > >>Share information about yourself, create your own public profile at > >>http://profiles.msn.com. > > > >In SAS you can use the verify function for that: > > > >data test; > > a="skjdhkj 1"; > > rc=verify(upcase(a),"ABCDEFGHIJKLMNOPQRSTUVWXYZ "); > > put rc=; > >run; > > > >This is much more flexible, because you can use your own definition, > >what is "alpha" (is $ alpha or not?). The second string contains all > >chars which you will allow. If you have a char in a which is not in the > >string, you will get the position of the unallowed char in a, or lets > >say "true". So you can use: > > > >if not verify ... > > > >verify returns "false" if the string only contains allowed chars.

_________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

Share information about yourself, create your own public profile at http://profiles.msn.com.


Back to: Top of message | Previous page | Main SAS-L page