I want to built a function to remove the duplicates in a string. In data step, the logic works well, however when I transfer it into function, it did not work. Does someone help me to figure out? thanks Below is the data step: ******************************************************************* data a; string = "spanner,span,spaniel,span,abc,span,bcc"; string2=string; length word $100; i = 2; do while(scan(string2, i, ',') ^= ''); word = scan(string2, i, ','); do j = 1 to i - 1; if word = scan(string2, j, ',') then do; start = findw(string2, word, ',', findw(string2, word, ',', 't') + 1, 't'); string2 = cats(substr(string2, 1, start - 2), substr(string2, start + length(word))); end; end; i = i + 1; end; keep string string2; run; ************************************************************************** Below is the function I want to built: *************************************************** proc fcmp outlib=work.funcs.rem_dup; function rem_dup(string $) $; string2=string; length word $100; i = 2; do while(scan(string2, i, ',') ^= ''); word = scan(string2, i, ','); do j = 1 to i - 1; if word = scan(string2, j, ',') then do; start = findw(string2, word, ',', findw(string2, word, ',', 't') + 1, 't'); string2 = cats(substr(string2, 1, start - 2), substr(string2, start + length(word))); end; end; i = i + 1; end; return(string2); endsub; run; ************************************************** Call the function: ************************************** options cmplib=(work work.funcs); data B; string = "spanner,span,spaniel,span,abc,span,bcc"; string2=rem_dup(string); run;
... View more