jingju11 发表于 2014-12-3 13:21 
if counting blank space: jingju
Using Char function in this case could save 30% cpu time.
128 data _null_;
129 x ='oops soooo-full';
130 z =substr(x,1,1);
131 do _i_=1 to 5e5;
132 k=1;
133 do i =2 to length(x);
134 if substr(x,i-1,1) =substr(x,i,1) then continue;
135 k ++1;
136 substr(z,k,1)=substr(x,i,1);
137 end;
138 end;
139 put x "--->" z;
140 run;
oops soooo-full --->ops so-ful
NOTE: DATA statement used (Total process time):
real time 1.27 seconds
cpu time 1.26 seconds
141
142 data _null_;
143 x ='oops soooo-full';
144 z =substr(x,1,1);
145 do _i_=1 to 5e5;
146 k=1;
147 do i =2 to length(x);
148 if char(x,i-1) =char(x,i) then continue;
149 k ++1;
150 substr(z,k,1)=char(x,i);
151 end;
152 end;
153 put x "--->" z;
154 run;
oops soooo-full --->ops so-ful
NOTE: DATA statement used (Total process time):
real time 0.95 seconds
cpu time 0.93 seconds