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

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
  • 5 replies
  • 6089 views
  • 2 likes
  • 4 in conversation