Hello so I'm attempting to modify code from a solution on the community to remove operators from a lab result variable (LBSTRESC) and then convert it to numeric , if possible, within one step. Here is what I have so far
data have;
input id lbstresc $40.;
datalines;
1 >=9.0
2 >=500
3 >75
4 <0.03
5 <= 500
;
run;
data want;
set have;
n_name = lbstresc;
length word $40 ;
do word='>', '>=', '<', '<=';
n_name = tranwrd(' '||n_name,' '||strip(word)||' ', ' ');
end;
n_name = compbl(n_name);
drop word ;
run;
This approach only works for row 5 as there is a space between the operator and the numerical result.
However, this is only a row I've inserted to highlight the problem and LBSTRESC for rows 1 to 4 are reflective of the actual data. What do I do to modify the tranwrd statement so the operators are removed in n_name?
Is so then simply do
data have;
input id lbstresc $40.;
datalines;
1 >=9.0
2 >=500
3 >75
4 <0.03
5 <= 500
;
data want;
set have;
w = input(compress(lbstresc, '.', 'kd'), 8.);
run;
You just want the numbers 9.0, 500 and so on in a numeric type, correct?
Yes, that's right
Does my code below work for you?
Is so then simply do
data have;
input id lbstresc $40.;
datalines;
1 >=9.0
2 >=500
3 >75
4 <0.03
5 <= 500
;
data want;
set have;
w = input(compress(lbstresc, '.', 'kd'), 8.);
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 lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.