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".
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.