Instead of 190 to 194,we can write below: DRGX=DRGX+((DRGX<MANX)-(DRGX>MANX))*DPSD DRGY=DRGY+((DRGY<MANY)-(DRGY>MANY))*DPSD