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? |
|---|---|
| 220790101003023 | yes |
| 040159507041388 | yes |
| (null) | no |
| 21071920100j011 | no |
| 481210201053003 | yes |
Thanks!
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
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
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
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;
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;
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
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.