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;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.