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
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
;
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;
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.