Showing posts with label data step trick. Show all posts
Showing posts with label data step trick. Show all posts

Thursday, April 30, 2009

SAS to keep only valid characters in a String

/* These are the only valid characters */
%let validchars = 'a' 'b' '1' '2' '_' '$';


data validchars;
string = "abc123_*";
str_len = length(string );


do while( str_len > 0);
if substr(string, str_len,1) not in (&validchars )then substr(string,str_len,1) = " ";
str_len = str_len -1;
end;
string = compbl(string);
/*Removing multiple blanks */
run;
proc print;
run;