BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

Dear,

 

I need help in my code. In my data, a variable (test) contain some characters that I need to remove. Please help.

 

test

 

BMI_RAW

DIABP1_RAW

DIABP2_RAW

SYSBP2_RAW

SYSBP1_RAW

SYSBP3_RAW

 

OUTPUT NEED;

TEST1

BMI

DIABP

DIABP

SYSBP

SYSBP

SYSBP

 

MY CODE;

TEST1=strip(tranwrd(TEST, "_RAW", ""));

 

I AM GETTING OUTPUT;

BMI

DIABP1

DIABP2

SYSBP1

SYSBP2

SYSBP3

 

Please help. Thanks

 

 

 

 

4 REPLIES 4
Jagadishkatam
Amethyst | Level 16
Please try compress
TEST1=compress(strip(tranwrd(TEST, "_RAW", "")),'ka');
Thanks,
Jag
Jagadishkatam
Amethyst | Level 16

alternatively by perl regular expressions

 

data have;
input text:$100.;
if prxmatch('/[1-9]|\_\RAW/',text) then new=prxchange('s/[1-9]|\_\RAW//',-1,text);
cards;
BMI_RAW
DIABP1_RAW
DIABP2_RAW
SYSBP2_RAW
SYSBP1_RAW
SYSBP3_RAW
;
Thanks,
Jag
RahulG
Barite | Level 11

I have used Pearl regular expression function

d?_RAW   means it would check string having zero or one digit (d? ) then followed by _RAW.

 

 

data have;
input test $16.;
datalines;
BMI_RAW
DIABP1_RAW
DIABP2_RAW
SYSBP2_RAW
SYSBP1_RAW
SYSBP3_RAW
;

data want(drop=RegularExpressionId);
set have;
   RegularExpressionId = prxparse('s/\d?_RAW/ /');
   call prxchange(RegularExpressionId, -1, test );
   put test ;
run;

 

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 1111 views
  • 3 likes
  • 4 in conversation