From: Arthur Tabachneck on
You could use something like:

data want;
set have;
if length(var1) eq 3 and notdigit(var1) eq 4;
run;

HTH,
Art
--------
On Thu, 24 Dec 2009 09:13:41 -0500, William Shakespeare
<shakespeare_1040(a)HOTMAIL.COM> wrote:

>I have a column in my data that is a 9 character string:
>
>var1
>12345
>abc
>6
>xyz
>123
>
>I need to find every value that has a length of 3 characters and then test
>to see if each character is in 0-9 (or more concisely, test to see if it
>is a 3 digit number). I can do the parsing and testing but I'm not sure
>how to grab only the values that are 3 characters or even if that's
>necessary. Ideas?
From: rjf2 on
> From: William Shakespeare
> Subject: string parsing

> I have a column in my data that is a 9 character string:

> var1
> 12345
> abc
> 6
> xyz
> 123

> I need to find every value that has a length of 3 characters
> and then test to see if each character
> is in 0-9 (or more concisely,
> test to see if it is a 3 digit number).
> I can do the parsing and testing
> but I'm not sure how to grab only the values
> that are 3 characters or even if that's necessary. Ideas?

If not verify(substr(Var1,1,3),'0123456789') then ...;

Squint at the logic: verify returns position of chars not in the valid
string
Thus the not.

I like Art's use of the function anydigit
Since its use does not require you to visually parse the valid string:
'1234567890'

The less proofreading the better!

Ron Fehd the function maven
From: dkw0 on
> I have a column in my data that is a 9 character string:
>
> var1
> 12345
> abc
> 6
> xyz
> 123
>
> I need to find every value that has a length of 3 characters and then
> test to see if each character is in 0-9 (or more concisely, test to
see
> if it is a 3 digit number). I can do the parsing and testing but I'm
> not sure how to grab only the values that are 3 characters or even if
> that's necessary. Ideas?


I like regular expressions, so here's how I'd do it:


data have;
length x $ 9;
input x;
if prxmatch("/^\d\d\d$/o", strip(x) );
datalines;
var1
12345
abc
6
xyz
123
;
run;
proc print data=have;
run;