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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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