/* convert any non-alphabet chars to a blank */
data _null_;
v1 = "YT;-/*ADD^)M";
v2 = prxchange("s/[^A-Z]/ /",-1,v1);
put (_all_) (=/);
run;
Below two coding options for replacing any non alphanumeric character (or underscore) with a blank.
If below sample code doesn't work for your real data then please be very specific what's not working and ideally provide amended sample data that demonstrates where the current result doesn't meet your desired result.
data _null_;
input have :$40.;
/* create target variables with same type and length than source variable */
if 0 then
do;
want1=have;
want2=have;
end;
/* option for single byte characters only */
want1=prxchange('s/\W/ /',-1,strip(have));
/* option that also allows for multi byte characters */
want2=ktranslate(strip(have), ' ', kstrip(kcompress(have, ,'n')));
/* print want variables */
file print;
put
'have: ' @10 have /
'want1: ' @10 want1 /
'want2: ' @10 want2 /
'-------------------------'
;
datalines4;
YT;-/*ADD^M
Y9;-/*A;;D@D^M
;;;;
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.