S&P 500 ends lower as investors weigh data, Middle East tensions