|
地板

楼主 |
发表于 2012-1-6 21:40:15
|
只看该作者
Re: 如何在一个string里挑选distinct值?
the sub-string in the list is not sorted. If you want so, please refer to the method of bubble sorting above.
[code:1u06edel]data a;
raw_str=' 000 aaaa 3 th 1234 000 a3b4 3 aa 1234 0 aa ';
str=compbl(left(trim(raw_str)));
run;
data b(drop=i);
set a;
sub_str_cnt=0;
do i=1 to length(str);
if substr(str,i,1)=' ' then sub_str_cnt=sub_str_cnt+1;
end;
sub_str_cnt=sub_str_cnt+1;
run;
data _null_;
set b end=last_rec;
retain array_size .;
if array_size<sub_str_cnt then array_size=sub_str_cnt;
if last_rec then call symput('n', array_size);
run;
%put &n;
data c(drop=i j k sub:);
set b;
array sub_str{&n} $10. /*_temporary_*/;
i=1;
j=1;
do k=1 to sub_str_cnt-1;
do while (i<length(str));
if substr(str,i,1)=' ' then do;
sub_str(k)=substr(str,j,i-j);
i=i+1;
j=i;
leave;
end;
i=i+1;
end;
end;
sub_str(sub_str_cnt)=substr(str,j,length(str)-j+1);
do i=1 to &n.-1;
do j=i+1 to &n;
if sub_str(i)=sub_str(j) then sub_str(j)='';
end;
end;
length mod_str $100.;
mod_str='';
do i=1 to &n;
mod_str=compbl(left(trim(mod_str))||' '||compress(sub_str(i)));
end;
run;
[/code:1u06edel] |
|