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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.