The S&P 500 and Nasdaq advanced on Thursday, building on their best day in eight weeks in the previous session as data showed an improvement in pending home sales and a drop in initial jobless claims.

The National Association of Realtors said pending sales of previously owned homes rose unexpectedly in July while initial jobless claims fell for a second straight week, though they remained at historically elevated levels.

Home Depot Inc was the Dow's top percentage gainer, climbing 1.9 percent to $29.22.

The housing market continues to be very challenging, but at least it appears to be stabilizing, said Lawrence Glazer, managing partner at Mayflower Advisors in Boston. I think a lot of people are going to think they've been too pessimistic.

The housing and labor markets have long been considered two of the biggest headwinds facing the recovery, and the data comes a day ahead of a monthly employment report expected to confirm that jobs were lost in August.

The Dow Jones industrial average <.DJI> was down 2.50 points, or 0.02 percent, at 10,266.97. The Standard & Poor's 500 Index <.SPX> was up 3.50 points, or 0.32 percent, at 1,083.79. The Nasdaq Composite Index <.IXIC> was up 9.84 points, or 0.45 percent, at 2,186.68.

In an encouraging sign for the consumer, U.S. retailers posted better-than-expected sales in August as consumers sought bargains during the key back-to-school season.

Today's data is positive, but given the high level of unemployment, it's hard to be too optimistic about the consumer, said Michael Sheldon, chief market strategist at RDM Financial in Westport, Connecticut.

The Morgan Stanley Retail index <.MVR> rose 1.6 percent while the S&P retail index <.RLX> added 1.6 percent. Apparel retailer Gap Inc advanced 1.6 percent to $17.49, though teen-oriented retailer Abercrombie & Fitch Co sank 5.2 percent to $34.67.

On the merger front, Burger King Holdings Inc agreed to sell itself to investment firm 3G Capital for about $3.26 billion, pushing the stock up 24.3 percent to $23.44.

In the end to an extended bidding war, Hewlett-Packard Co raised its buyout offer for data storage company 3PAR Inc
to $33 a share, topping an earlier bid from Dell Inc . The higher bid prompted Dell to bow out.

Shares of 3PAR rose 2.4 percent to $32.84 while Dell gained 2.2 percent to $12.38.

HP, a Dow component, rose 0.5 percent to $39.39.

(Reporting by Ryan Vlastelica; Editing by Jan Paschal)