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:
-> 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;
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;
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;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.