Or something like:
data want;
set have;
if not missing(input(var, ?? best.));
run;
Hi @amol2939
Here is an approach to achieve this:
data have;
input lab_result $;
datalines;
abc
123
def
789
a1
;
run;
data want;
set have;
if prxmatch('/^\d+\s*$/',lab_result) then output;
run;
Output:
Capture d’écran 2020-03-18 à 10.16.19.png
-> nb: the column will be still a character one, even if it display only numbers
->the prxmatch function looks for the pattern /^\d+\s*$: , meaning:
A string starting (^) with one or more (+) digits (\d) and zero, one or more (*) trailing blanks (\s) at the end ($) of the string.
Hope this helps,
Best,
If your data are more like this, here is another solution:
data have; infile datalines dlm="," truncover; input lab_result :$80.; datalines; abc 123 abc 456 123 abc def 123 ; run; data want; set have; array digits(4); do i=1 to countw(lab_result); digits(i)=scan(lab_result, i, , 'dko'); end; drop i; run;
Capture d’écran 2020-03-18 à 10.35.20.png
OR
data have;
infile datalines dlm="," truncover;
input lab_result :$80.;
datalines;
abc 123 abc 456
123 abc
def 123
;
run;
data want;
set have;
digits = compress(lab_result,,"dK");
run;
Capture d’écran 2020-03-18 à 10.37.17.png
Best,
Or something like:
data want;
set have;
if not missing(input(var, ?? best.));
run;
data have;
input lab_result $;
datalines;
abc
123
def
789
a1
;
run;
data want;
set have;
if notdigit(strip(lab_result)) then delete;
run;
CFC_SAS_Communities_400x225.jpg
It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.