Dear,
In my data, I need remove some characters from a variable (test) values. With my code I am not getting output I need for ONE observation.
Please look at OBS 4 (test=EXCL08C). i AM NOT GETTING THE OUTPUT I NEED FOR THIS.
Please help.
data
test
EXCL01
EXCL07B
EXCL08
EXCL08C
EXCL10
MY CODE;
if test =:'EXCL0' THEN TEST1=COMPRESS(TEST,'XCL0','');
ELSE IF test ^=:'EXCL0' THEN TEST1=COMPRESS(TEST,'XCL','');
RESULT;
E1
E7B
E8
E8
E10
OUTPUT NEED;
E1
E7B
E8
E8C
E10
You may be better off using a SUBSTR() function?
Looks like you're taking first character and then everything after the 4th?
I'm not sure this will easily extend if needed but works for the example data;
data example;
informat test $10.;
input test;
result = tranwrd(test,'EXCL0','E');
result = tranwrd(Result,'EXCL','E');
datalines;
EXCL01
EXCL07B
EXCL08
EXCL08C
EXCL10
;
data example;
informat test $10.;
input test;
result = prxchange('s/XCL0*//i',-1,test);
datalines;
EXCL01
EXCL07B
EXCL08
EXCL08C
EXCL10
;
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.