The Standard & Poor's 500 index had moved above its previous record many times this week, only to fade in the afternoon. On Thursday, it finally closed above the milestone, powered by strong earnings from a number of U.S. companies including the drugmaker Mylan and several retailers.