Help using Base SAS procedures

How to check if first character is numeric?

Reply
N/A
Posts: 0

How to check if first character is numeric?

I'm using this statement to get back the first character in an address field.
I'm having a problem finding a way to verify what it is.
char1=substr(addr,1,1);

I tried this :

if (input(addr, 1.) eq .) then
a='non-numeric';
else
a ='numeric';

When I try this I get a lot of
"NOTE: Invalid argument to function INPUT at line 1063 column 9." How can I get it to have a clean execution?

Thank You
Respected Advisor
Posts: 3,799

Re: How to check if first character is numeric?

Posted in reply to deleted_user
Use ?? in format field of INPUT function. You may want to look a VERIFY function also.

> I'm using this statement to get back the first
> character in an address field.
> I'm having a problem finding a way to verify what it
> is.
> char1=substr(addr,1,1);
>
> I tried this :
>
> if (input(addr, ??1.) eq .) then
> a='non-numeric';
> e
> a ='numeric';
> hen I try this I get a lot of
> "NOTE: Invalid argument to function INPUT at line
> 1063 column 9." How can I get it to have a clean
> execution?
>
> Thank You
N/A
Posts: 0

Re: How to check if first character is numeric?

Posted in reply to data_null__
Thank you for replying data _null_.
I was just about to post my solution which consists of the VERIFY function.

char1=substr(addr1,1,1);

if verify(trim(left(char1)),'0123456789')=0 Then
a='numeric';
else
a ='char';

Thank You
Jerry
Respected Advisor
Posts: 3,799

Re: How to check if first character is numeric?

Posted in reply to data_null__
ANYDIGIT function would probably be faster. If you are just looking at the first position. The technique you are using is better for test if a string is a number, so strings like 1e4 would be read correctly. If your numbers could include commas or dollar sign use COMMA informat.

If you are trying to see if string is a SAS name NVALID function.

[pre]
data _null_;
input string $16.;
x = anydigit(string);
if anydigit(string) eq 1 then put 'Digit in First Position' string=;
put (_all_)(=);
cards;
1e000
e1000
.This
This
;;;;
run;
[/pre]
N/A
Posts: 0

Re: How to check if first character is numeric?

Posted in reply to data_null__
Data,
What i'm trying to do is check if the first character in my address field is truley a number or is it a character. We are trying to clean the data up and i'm trying to find all the address that start with a letter since mostly all address start with a number.

For what i'm trying to do is mine way correct? With anydigit would I have to check every digit ex. 1,2,3,4,5 etc..?
Ask a Question
Discussion stats
  • 4 replies
  • 4464 views
  • 0 likes
  • 2 in conversation