|
What I like about verify() in this situation, is that its name
indicates its purpose....So it might be considered "self-documenting".
I think the "choice" of comma. or best. is only properly
"informed" by the underlying requirement... which has not
been revealed....
.... perhaps a 40 digit numeric string is being validated
.... perhaps the informat should be comax allowing european
thousand and decimal separators
Hints like "How do I check if a variable is numeric?"
indicate that perhaps things are happening at the wrong level (imho)....
A variable is considered "initialized" until it has a type.
Therefore if it's type is unknown, then it isn't a "variable". It is
data . The uncertainty can and must, be resolved _before_
the step which assigns the data to a variable.
....................
Regards
Peter Crawford
Datum: 18/11/2002 15:09
An: SAS-L@LISTSERV.UGA.EDU
Antwort an: "roland.rashleigh-berry" <roland.rashleigh-berry@NTLWORLD.COM>
Betreff: Re: Is a variable Numeric?
Nachrichtentext:
verify() is also good.
You would maybe be better off using input(var,?? comma32.) rather than
"best" since it will also accept good numbers with the comma notation such
as 12,123.08 but what you suggest is an improved method.
"Peter Crawford" <peter.crawford@DB.COM> wrote in message
news:OF5473CF6A.26298DB3-ON41256C75.00354FC2@db.com...
> Hi Roland
>
> had you considered the verify function ?
> posn_not_in_list = verify( source_var, '0123456789.+.' );
> Of course, many "numeric" informats allow non-numeric chars
> like the letters D, E and perhaps others ($) .
>
> However, I think the verify() function was designed
> for the purpose of detecting "non-standard" characters
> in a string....... like this posters question
> .....
> and however, I'm not sure about the point of such
> validation, over the more informative
> value = input( var, ?? best32. );
> as it also provides the actual value, when present......
> and is less likely to accept -12--+-45+.+78.
> as in
> 134 data;
> 135 do source_var= '-12--+-45+.+78.'
> 136 , '1234567890.1234'
> 137 , '1234567890';
> 138 posn_not_in_list = verify( source_var, '1234567890.+-' );
> 139 value = input( source_var, ?? best32. );
> 140 put (_all_ )(=);
> 141 end;
> 142 run;
>
> source_var=-12--+-45+.+78. posn_not_in_list=0 value=.
> source_var=1234567890.1234 posn_not_in_list=0 value=1234567890.1
> source_var=1234567890 posn_not_in_list=11 value=1234567890
> NOTE: The data set....................
>
> Regards
> Peter Crawford
>
>
> Datum: 18/11/2002 10:39
> An: SAS-L@LISTSERV.UGA.EDU
>
>
>
>
> Antwort an: "roland.rashleigh-berry"
<roland.rashleigh-berry@NTLWORLD.COM>
>
> Betreff: Re: Is a variable Numeric?
> Nachrichtentext:
>
> "âãé áï àáé" <GADI_B@MALAM.COM> wrote in message
>
news:B3A415965C0CBC46AE5D76C9B90166AD215C96@jer-mailbox1.jer.ad.malam.com...
> Hi all,
>
> Q: How do I check if a variable is numeric?
>
> A: You can use the "vartype()" function.
>
> Q: How do I check if a text variable has numeric content (only digits, a
> period and a sign)?
>
> A: if compress(var,'0123456789.+-') EQ ' ' then...
>
>
>
>
>
> --
>
>
>
>
--
Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail ist nicht gestattet.
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
|