Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Verify data is all numbers.....

Status
Not open for further replies.

dherna

Technical User
May 1, 2002
6
US
Hi,

How can I verify that the data in an alpha-numeric field is all numbers?

Di--
 
I've used the following developed macro's with good success
in the past. Hope this helps.


PROC FORMAT ;
VALUE $XXX '0'-'9' ='NUM' ;
RUN;
...

%*------------- ;
%MACRO NUMCHKS ;
%*------------- ;
CHK_FLAG='N';
DO X=1 TO LENGTH(<fieldname>);
IF PUT(SUBSTR(<fieldname>,X,1),$XXX.) NE 'NUM'
THEN DO;
CHK_FLAG='Y';
X=99;
END;
%*------------- ;
%MEND NUMCHKS ;
%*------------- ;
...
%NUMCHKS(<fieldname>);

/* ------------------- O R ------------------------*/
...
%LET DIGIT = ('0','1','2','3','4','5','6','7','8','9');
...
%*------------- ;
%MACRO VALIDITY ;
%*------------- ;
SIZE=LENGTH(COMPRESS(<fieldname>));
IF (SIZE GT 1)
THEN DO;
VALIDFLG='Y';
DO I = 1 TO SIZE;
IF NOT (SUBSTR(COMPRESS(<fieldname>),I,1)
EQ &DIGIT)
THEN DO;
VALIDFLG='N';
I=99;
END;
END;
ELSE VALIDFLG='N';
DROP I VALIDFLG ;
%*------------- ;
%MEND VALIDITY ;
%*------------- ;
...
%VALIDITY(<fieldname>);
...


 
DATA test;
set yourdata;
if verify(alpha,'0123456789')=0 then test= 'OK';
RUN;
 
data test;
length x1 $ 7;
x1='12b345';
if x1*1> . then
put &quot;*** OK&quot;;
else put &quot;Nok&quot;;

run;
This program don't post ERROR messages but Notes messages
into the log.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top