Stocks edged higher on Tuesday as better-than-expected data on home sales underpinned signs of an economic recovery, but the gains were capped as investors took profits in shares that propelled the recent rally.

Investors sold shares in the technology, materials and energy sectors after Monday's run-up extended the benchmark S&P 500's <.SPX> rally of nearly 48 percent since early March.

The Dow Jones U.S. Home Construction index <.DJUSHB> rose 2.4 percent, erasing earlier losses, after the June pending home sales report.

Pending sales of previously owned U.S. homes rose at a faster-than-expected pace in June, advancing for the fifth straight month for the first time in six years, according to the National Association of Realtors.

For those that look at housing as the catalyst from which we have to emerge, this is going to be considered a positive, said Marc Pado, U.S. market strategist at Cantor Fitzgerald & Co in San Francisco.

Also, the Commerce Department reported that U.S. consumer spending rose slightly more than expected in June, though personal income declined month over month by a greater-than-expected 1.3 percent.

The Dow Jones industrial average <.DJI> rose 22.45 points, or 0.25 percent, to 9309.24. The Standard & Poor's 500 Index <.SPX> gained 3.02 points, or 0.3 percent, to 1005.66. The Nasdaq Composite Index <.IXIC> was up 1.50 points, or 0.08 percent, to 2,008.61.

Energy shares were among the top drags as U.S. front-month crude seesawed.

Oil majors Chevron Corp fell 0.4 percent at $70.12, and Exxon Mobil Corp dipped 0.2 percent to $70.46.

I think the issue for the market is we're right at 1,000 for the S&P 500 and that may represent a psychological feeling for the market for at least the very short term, said Michael Sheldon, chief market strategist at RDM Financial in Westport, Connecticut.

Among advancers, PepsiCo Inc
was up 4.8 percent at $58.90 after it said it agreed to buy Pepsi Bottling Group Inc
and PepsiAmericas Inc
in a cash-and-stock deal with $7.8 billion.

Shares of Pepsi Bottling gained 8.1 percent.

Apple Inc was down 0.7 percent at $165.23.

(Editing by Padraic Cassidy and Jeffrey Benkoe)