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;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.