BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
smackerz1988
Pyrite | Level 9

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.

 

smackerz1988_0-1662716564920.png

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?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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;

View solution in original post

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

You just want the numbers 9.0, 500 and so on in a numeric type, correct?

PeterClemmensen
Tourmaline | Level 20

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;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

Register now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1251 views
  • 1 like
  • 2 in conversation