BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SAShole
Pyrite | Level 9

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

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

5 REPLIES 5
Haikuo
Onyx | Level 15

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

Hima
Obsidian | Level 7

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

Haikuo
Onyx | Level 15

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;

Hima
Obsidian | Level 7

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;

Ksharp
Super User

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

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 7495 views
  • 2 likes
  • 4 in conversation