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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.