data s ;
input id $ result $ ;
cards ;
111 482
112 854
113 neg
114 pos
115 45.5
;
extract numeric values and character values from result variable?
data s ;
input id $ result $ ;
cards ;
111 482
112 854
113 neg
114 pos
;
data want;
set s;
n=compress(result,' ','kd');
c=compress(result,' ','d');
run;
Show what the output should look like. Do you want a numeric column with those which are numeric converted? Would you like separate datasets, etc? For columns:
data want;
set s;
if not anyalpha(result) then num_var=input(result,best.);
run;
Hi,
Check below code
data want;
set s;
if input(result, best.) then numeric = result;
else char = result;
run;
You have warnings in that code though about converting text to numeric, actually I fell into the same trap as I forgot that ifn() will do the conversion regardless of the if part. I updated my code to avoid this.
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.