BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Srikanth_J
Calcite | Level 5
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.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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;

View solution in original post

5 REPLIES 5
novinosrin
Tourmaline | Level 20

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;
Tom
Super User Tom
Super User

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
;
ed_sas_member
Meteorite | Level 14

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;
Ksharp
Super User
data have;
input name $9.;
name2 = prxchange('s/\b(ae)\b/\U\1/',-1,name);
cards;
aedef
ae
sae
dftaes ae
aerae
;
run;
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1517 views
  • 3 likes
  • 5 in conversation