When you say 'Special Symbols', do you simply mean *, @, &, # or?
One way is to use PRXCHANGE like this. You can add more symbols of you like.
Data have;
String1='aaaaa*bbbb*ddddddd@jjjjjj';
String2='&aaaa*ggggghgg####';
Run;
data want;
set have;
String1 = prxchange('s/[*@&#]/ /', -1, String1);
String2 = prxchange('s/[*@&#]/ /', -1, String2);
run;
Converseley, you can indicate which characters you do not want to be replaced by spaces.
For instance, the following program wil replace all characters but alphanumerics and '_' with spaces :
data want;
set have;
String1 = prxchange('s/[^\w]/ /', -1, String1);
String2 = prxchange('s/[^\w]/ /', -1, String2);
run;
You can use the TRANSLATE() function to replace characters.
Example:
data have;
input string $40. ;
cards;
aaaaa*bbbb*ddddddd@jjjjjj
&aaaa*ggggghgg####
;
data want ;
set have;
new_string=translate(string,' ','*&#@');
run;
Results:
Obs string new_string 1 aaaaa*bbbb*ddddddd@jjjjjj aaaaa bbbb ddddddd jjjjjj 2 &aaaa*ggggghgg#### aaaa ggggghgg
If you are not sure what to replace perhaps you use the COMPRESS() function to get the list of non-alpha characters in the string.
data want ;
set have;
new_string=translate(string,' ',compress(string,,'ad'));
run;
@thanikondharish wrote:
Data have;
String1='aaaaa*bbbb*ddddddd@jjjjjj';
Output;
String2='&aaaa*ggggghgg####';
Output;
Run;
How to replace special symbols by space
SHOW the required output or explicitly list which characters you consider "special characters". For some purpose I might consider "a" as a "special character".
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.