The latest economic data failed to impress buyers. U.S. claims for initial jobless benefits fell to a seasonally adjusted 284,000, the lowest since mid-February 2006. New home sales declined 8.1 percent in June, the biggest drop in almost a year. The PHLX housing sector index <.HGX> lost 2.7 percent, marking its biggest one-day drop since February.

Recent gains on Wall Street have been fueled by earnings, which have been strong this quarter. With 41 percent of S&P 500 companies having reported results so far, 68 percent have posted earnings that topped expectations, according to Thomson Reuters data, above the long-term average of 63 percent. On the revenue side, 62.1 percent have beaten analysts' forecasts, compared with the historical average of 61 percent.

Facebook Inc (>> Facebook Inc) jumped 5.2 percent to $74.98 and hit an intraday record high of $76.74 a day after the world's No. 1 social network reported earnings and revenue that beat expectations.

Caterpillar Inc (>> Caterpillar Inc.) raised its full-year outlook but posted a decline in sales, pushing its stock down 3.1 percent to $105.04. The Dow component is the world's largest maker of earth-moving equipment.

"There's a tug of war in the market today between the companies that did well and the companies that didn't. Caterpillar was disappointing, but stocks remain reasonably valued and the earnings season supports continued gains," said Kate Warne, investment strategist at Edward Jones in St. Louis.

The Dow Jones industrial average <.DJI> dipped 2.83 points or 0.02 percent, to close at 17,083.80. The S&P 500 <.SPX> gained 0.97 of a point or 0.05 percent to end at 1,987.98, its second record closing high in a row. The Nasdaq Composite <.IXIC> shed 1.59 points or 0.04 percent, to finish at 4,472.11.

At its record intraday high of 1,991.39, the S&P 500 was just 0.4 percent below the 2,000 milestone.

Among the companies that reported results after the closing bell, Amazon.com Inc (>> Amazon.com, Inc.) shares fell 9.7 percent to $324 after the online retailer reported a second-quarter loss that was wider than expected.

Visa Inc (>> Visa Inc), the world's largest credit and debit card company, reported earnings growth of 11 percent, but the Dow component's stock fell 3.3 percent to $215.33 in extended-hours trading. Starbucks Corp (>> Starbucks Corporation) posted revenue that was slightly higher than expected. The coffee chain's stock slipped 0.7 percent to $79.91 in after-hours trading.

Baidu Inc (>> Baidu Inc (ADR)) rose 6.4 percent to $217.35 in extended-hours trading after China's biggest Internet search company reported results that were much stronger than had been expected.

During the regular session, stocks that made big moves after earnings included Under Armour Inc (>> Under Armour Inc) - up 14.7 percent at $69.55 after the sports apparel manufacturer and retailer reported a sharp rise in revenue. Under Armour's stock hit an all-time intraday high of $70.25 and was the S&P 500's biggest gainer.

The benchmark S&P 500's biggest decliner was homebuilder D.R. Horton Inc (>> D.R. Horton, Inc.), which tumbled 11.5 percent to $21.94 after the company reported a 23 percent slide in profits. The results gave investors a reason to unload some homebuilders' shares.

General Motors Co (>> General Motors Company) dropped 4.5 percent to $35.74 after the company reported a much lower second-quarter profit because of numerous recalls and the expected cost of at least $400 million for its victims' compensation fund.

Almost 51 percent of stocks listed on the New York Stock Exchange ended the day lower, while 52 percent of Nasdaq-listed shares ended in negative territory.

About 5.58 billion shares traded on all U.S. platforms, according to BATS exchange data, compared with the month-to-date average of 5.54 billion.

(Editing by Jan Paschal)

By Ryan Vlastelica