Help using Base SAS procedures

Identifying non-numeric values

Accepted Solution Solved
Reply
Contributor
Posts: 62
Accepted Solution

Identifying non-numeric values

Hi all,

I have a field that should contain only numeric values but is set to character to preserve leading zeros. i would like to identify records that do not contain 0-9 values.

data have;

    input block $15.;

    cards;

220790101003023

040159507041388

(null)

21071920100j011

481210201053003

run;

want:

block                numeric?
220790101003023yes
040159507041388yes
(null)no
21071920100j011no
481210201053003yes

Thanks!


Accepted Solutions
Solution
‎03-30-2012 02:01 PM
Respected Advisor
Posts: 3,124

Identifying non-numeric values

Try this:

data have;

    input block $15.;

    cards;

220790101003023

040159507041388

(null)

21071920100j011

481210201053003

run;

data want;

set have;

length numeric $3;

Numeric=ifc(missing(compress(block,,'d')),'Yes','No');

run;

proc print;run;

Regards,

Haikuo

View solution in original post


All Replies
Solution
‎03-30-2012 02:01 PM
Respected Advisor
Posts: 3,124

Identifying non-numeric values

Try this:

data have;

    input block $15.;

    cards;

220790101003023

040159507041388

(null)

21071920100j011

481210201053003

run;

data want;

set have;

length numeric $3;

Numeric=ifc(missing(compress(block,,'d')),'Yes','No');

run;

proc print;run;

Regards,

Haikuo

Regular Contributor
Posts: 233

Re: Identifying non-numeric values

data have;
input block $15.;
cards;
220790101003023
040159507041388
.
21071920100j011
481210201053003
21071920100A011
run;

proc print; run;

data want;
set have;
LENGTH non_numeric $3.;
if prxmatch("m/a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z| /oi",block)>0
then non_numeric = 'NO';
ELSE non_numeric = 'YES';
run;

proc print; run;


OUTPUT:

                                                                        non_
                               Obs         block              numeric

                                1     220790101003023      YES
                                2     040159507041388      YES
                                3                                      NO
                                4     21071920100j011        NO
                                5     481210201053003      YES
                                6     21071920100A011      NO

Respected Advisor
Posts: 3,124

Identifying non-numeric values

Or:

data have;

input block $15.;

cards;

220790101003023

040159507041388

.

21071920100j011

481210201053003

21071920100A011

run;

data want;

set have;

if not missing(block) and not prxmatch("/\D/",block) then numeric='Yes';

else numeric='No';

run;

proc print;run;

Regular Contributor
Posts: 233

Re: Identifying non-numeric values

Hai.Kuo the below code is with out missing(block) is working fine.

data have;
input block $15.;
cards;
220790101003023
040159507041388
.
21071920100j011
481210201053003
21071920100A011
run;


data want;
set have;
if not prxmatch("/\D/",block) then numeric='Yes';
else numeric='No';
run;

proc print;run;

Super User
Posts: 9,671

Re: Identifying non-numeric values

SAS has already a function to handle this question.

data have;
input block $15.;
cards;
220790101003023
040159507041388
.
21071920100j011
481210201053003
21071920100A011
;
run;
data want;
 set have;
 flag=ifc(notdigit(block),'N','Y');
run;






Ksharp

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 1301 views
  • 1 like
  • 4 in conversation