@bodowd wrote:
Using compress with the whole alphabet at the first argument, your text as second argument, and 'k' modifier to keep letters for the alphabet as they appear.
data test;
input fname $ sname $ ;
datalines;
John Smith
Tom Bell
;
data test;
set test;
fullname = cats(fname, sname);
fullname2 = compress('AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz', fullname, 'k');
run;
@bodowd : Very nice, because you can trivially change the desired order of characters in the result:
data test;
set test;
fullname = cats(fname, sname);
fullname2 = compress('AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz', fullname, 'k');
fullname3 = compress('ZzYyXxWwVvUuTtSsRrQqPpOoNnMmLlKkJjIiHhGgFfEeDdCcBbAa', fullname, 'k');
run;
But be careful - In the absence of a LENGTH declaration, the resulting FULLNAME2 and 3 lengths are determined by the first argument of the compress function - i.e. length 52 in this case.
Also, letters that appear more than once in the original, appear only once in the result.
... View more