The S&P 500 and Nasdaq gained 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, advancing 2.3 percent to $29.32.

Housing has been a big source of disappointment lately, and since the pending home sales number wasn't bad, it has enabled yesterday's rally to follow through, said Gary Flam, portfolio manager of Bel Air Investment Advisors in Los Angeles.

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.

Claims are probably the best predictor we have for tomorrow's number, and they suggest we could at least see an in-line number, which would be viewed as a positive since data has been continually disappointing lately, Flam said.

The Dow Jones industrial average <.DJI> was up 9.61 points, or 0.09 percent, at 10,279.08. The Standard & Poor's 500 Index <.SPX> was up 5.38 points, or 0.50 percent, at 1,085.67. The Nasdaq Composite Index <.IXIC> was up 13.33 points, or 0.61 percent, at 2,190.17.

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.

The sales put to the sideline some of the fear about a double dip, said John Canally, investment strategist at Boston-based LPL Financial, in reference to concern the U.S. economy might slip back into recession..

Costco Wholesale Corp gained 0.6 percent to $58.12 after the largest U.S. warehouse club operator reported better-than-expected same-store sales.

Both the Morgan Stanley Retail index <.MVR> and the S&P retail index <.RLX> added 2 percent. Gap Inc advanced 1.9 percent to $17.53, though teen-oriented retailer Abercrombie & Fitch Co sank 4.7 percent to $34.85.

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.2 percent to $23.43.

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.41.

(Reporting by Ryan Vlastelica; Editing by Jan Paschal)