The Dow and the S&P 500 declined on Friday as May retail sales unexpectedly fell, though a better-than-expected read on June consumer sentiment and strength in tech lifted the Nasdaq.

Total retail sales marked their first monthly drop in eight months, falling 1.2 percent in May -- contrary to economists' consensus forecast for a gain of 0.2 percent. The data underlined concerns about the consumer's strength in the economic recovery.

The S&P Retail index <.RLX> fell 1 percent while Macy's Inc slid 0.4 percent to $21.19. Dow component Wal-Mart Stores Inc dropped 0.6 percent to $50.92.

The one-two punch of the retail sales and the recent payroll number makes this especially disappointing, said Marc Pado, U.S. market strategist at Cantor Fitzgerald & Co. in San Francisco.

In contrast to the weak retail sales, consumer sentiment improved more than expected, rising to its strongest point in over two years in June, according to a preliminary reading for the month from the Thomson Reuters/University of Michigan Surveys of Consumers.

This was the saving grace for the day and why we're not down more, Pado said. It shows that consumers are still optimistic about things getting better.

The Dow Jones industrial average <.DJI> was down 39.68 points, or 0.39 percent, at 10,132.85. The Standard & Poor's 500 Index <.SPX> was down 4.04 points, or 0.37 percent, at 1,082.80. The Nasdaq Composite Index <.IXIC> was up 4.84 points, or 0.22 percent, at 2,223.55.

The Nasdaq gained on strength in semiconductor stocks after National Semiconductor Corp forecast margins and revenues above estimates, signaling that demand is bouncing back after a miserable 2009 for the microchip industry.

The stock rose 3.5 percent to $14 while Altera Corp was up 2.4 percent at $24.24. The PHLX Semiconductor index <.SOXX> added 0.6 percent.

Big-cap pharmaceutical companies' shares also advanced after Barclays Capital upgraded the sector to positive from neutral, citing the revenue potential of new products.

Pfizer Inc was the Dow's top percentage gainer, rising 3 percent to $15.36, with Merck & Co not far behind -- up 1.1 percent at $34.64.

U.S.-listed shares of BP Plc climbed 2.8 percent to $33.69 as UK officials made supportive comments, even as scientists doubled estimates of the Gulf of Mexico's oil spill.

Elsewhere on the economic front, U.S. business inventories rose 0.4 percent to a 10-month high, slightly under the expectation for a 0.5 percent increase.

(Reporting by Ryan Vlastelica; Editing by Jan Paschal)