Thank you! That REMOVE was what I was looking for, even though I just ended up removing t'th solutions of the inner functions ue and le from summations:
start mhatx2(m,p,h,pi,e);
t5=j(m,1);
do x=1 to nrow(p);
i=T(1:m);
temp1=x-i;
ue=Kmod(temp1,h,pi,e)#p;
le=Kmod(temp1,h,pi,e);
t5=(sum(ue)-ue)/(sum(le)-le);
end;
return (t5);
finish;