Why 2 loops?
[pre]
data t;
array varr(3) $2;
input (varr1 varr2 varr3) ($);
FREEPOS=1; *position of next free slot;
do I=1 to 3;
if varr(I) ne '' then do; *there is a value to keep;
if I ne FREEPOS then do; *the value must be shifted;
varr(FREEPOS)=varr(I); *shift value;
varr(I)=''; *reset current position since value has moved;
end;
FREEPOS+1; *update position of next free slot;
end;
end;
put _ALL_;
cards;
x1 . x3
. y2 y3
. z2 .
run;