"The market has a good underlying tone," said Mike Levine, portfolio manager of Oppenheimer Equity Income Fund. "People feel like the economy is gaining some strength and the job market is getting better and corporate earnings should be pretty good."
Even in a quiet day of trading ahead of the Labor Day holiday, stocks eked out a gain.
The indexes opened higher, but eased soon after, as investors got the news that consumer spending fell and income growth slowed in July.
Traders also had their eye on the conflict in Ukraine, as a group of European Union foreign ministers accused Russia of invading the eastern region of the country and said Moscow should be punished with more economic sanctions.
The markets began to recoup some losses by midmorning, however, when a gauge of consumer sentiment showed greater optimism in August, particularly among higher-income groups. Some better-than-expected company earnings also lifted stocks.
Overall, the indexes wavered between small gains and losses throughout the afternoon.
"We're seeing a listless, pre-holiday market," said Drew Wilson, an investment analyst at Fenimore Asset Management.
The S&P 500 index finished up 6.63 points, or 0.3 percent, to 2,003.37. It closed above 2,000 for the first time on Tuesday and has gained 8.4 percent this year.
The Dow Jones industrial average gained 18.88 points, or 0.1 percent, to 17,098.45 on Friday, while the Nasdaq composite added 22.58 points, or 0.5 percent, to 4,580.27.
Stocks rose broadly, with all 10 sectors in the S&P 500 index higher for the day, led by utilities.
The gains marked the index's best August since 2000.
"It's been a good August," said Linda Duessel, senior equity market strategist at Federated Investors. "I imagine it's the end of the month and people closing their books are saying 'I better show I'm invested, we had a brand-new high this week,'" she said.
Nevertheless, some investors may be more hesitant next month. September is widely considered the stock market's worst.
Since World War II, the S&P 500 index has ended the month with a loss half of the time. Recently, however, September has been good to investors. The S&P 500 has turned in a September loss just twice in the last decade: in the depths of the financial crisis in 2008 and following a fight over raising the government's borrowing limit in 2011.