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;
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 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.