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
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 -
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;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.