BookmarkSubscribeRSS Feed
betty2
Calcite | Level 5

Hello,

How can I replace characters in string please.

SOURCE

DESTINATION

And

&

Country

C!

City

CI

Under

\

For exemple :

 

If the field contains : Country and City

I have to turn it into : C! & CI

 

Thanks  for your help

2 REPLIES 2
Oligolas
Barite | Level 11

Hi,

 

there are many ways. The easiest may be to use the tranwrd function

data test;
   length string string2 $50;
   string='Country and City';
   string2=string;
   string2=tranwrd(String2,'And','&');
   string2=tranwrd(String2,'Country','C!');
   string2=tranwrd(String2,'City','CI');
   string2=tranwrd(String2,'Under','\');
   put string2;
run;
________________________

- Cheers -

Ksharp
Super User

I would like to use PRXCHANGE(),which could handle a word ,not a string.

 

data test;
   length string string2 string3 $50;
   string='Country and Cityand';
   string2=tranwrd(String,'and','&');
   string3=prxchange('s/\band\b/&/',-1,string);
run;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

Register now

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
  • 2 replies
  • 859 views
  • 0 likes
  • 3 in conversation