BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
4 REPLIES 4
data_null__
Jade | Level 19
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
deleted_user
Not applicable
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
data_null__
Jade | Level 19
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]
deleted_user
Not applicable
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..?

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 13881 views
  • 0 likes
  • 2 in conversation