data chk;
input name $9.;
name = tranwrd(name,"ae","AE");
cards;
aedef
ae
sae
dftaes ae
aerae
;
run;
I need the output as below:
aedef,
AE,
sae,
dftaes AE,
aerae
I need change the case of word ae to AE only if it exists as a word but not in between a word
Thanks in advance,
J.
HI @Srikanth_J What you need is FINDW as opposed to TRANWRD
if findw(name,'ae') then substr(name,findw(name,'ae'),2)='AE';
/*Using your example*/
data chk;
input name $9.;
name2=name;
if findw(name2,'ae') then substr(name2,findw(name2,'ae'),2)='AE';
cards;
aedef
ae
sae
dftaes ae
aerae
;
run;
HI @Srikanth_J What you need is FINDW as opposed to TRANWRD
if findw(name,'ae') then substr(name,findw(name,'ae'),2)='AE';
/*Using your example*/
data chk;
input name $9.;
name2=name;
if findw(name2,'ae') then substr(name2,findw(name2,'ae'),2)='AE';
cards;
aedef
ae
sae
dftaes ae
aerae
;
run;
You can use the INDEXW() function to find the locations where ae appears as a word.
data chk;
input name $9.;
do while(indexw(name,'ae'));
substr(name,indexw(name,'ae'),2)='AE';
end;
cards;
aedef
ae
sae
dftaes ae
aerae
;
Hi @Srikanth_J
You can try this also
data chk;
input name $9.;
name2 = strip(prxchange('s/(^|\s)(ae)(\s|$)/ AE /',-1,name));
cards;
aedef
ae
sae
dftaes ae
aerae
;
run;
data have;
input name $9.;
name2 = prxchange('s/\b(ae)\b/\U\1/',-1,name);
cards;
aedef
ae
sae
dftaes ae
aerae
;
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!
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.