data test1;
set have(rename=(x=x_ id=id_ y=y_));
do i=1 to nobs;
set have point=i nobs=nobs;
if id_ ne id then do;
if x = x_ then do;
newid=cats(put(min(id_,id),best.),',',put(max(id_,id),best.));
_y=min(y_,y);
flg=1;
output;
end;
else if x ne x_ then do;
newid=cats(put(min(id_,id),best.),',',put(max(id_,id),best.));
_y=0;
flg=2;
output;
end;
end;
end;
run;
proc sort data=test1 out=test2(keep=newid x_ flg _y);
by newid x_ flg;
run;
data want(drop=flg newid x_ _y);
set test2;
by newid x_ flg;
id=tranwrd(newid,',',ifc(flg=1,'and','not',' '));
x=x_;
newy=_y;
if first.x_;
run;