S&P 500 companies’ earnings are mostly topping analysts’ estimates — but by the narrowest margin in roughly four years.