The U.S. trade gap shrank in August on record exports and claims for jobless benefits fell last week, according to government data on Thursday that showed the economy retaining some vigor despite housing market ills.

Even the hard-hit housing sector showed a hint of improvement with foreclosure filings down 8 percent last month from a 32-month peak in August, according to RealtyTrac, an online market of foreclosure properties.

But other data was less upbeat.

Import prices rose more than expected in September, boosted by rising petroleum prices, while leading U.S. retailers, hurt by unusually warm weather that cut into demand for apparel, rang up dismally low sales.

Some retailers cut their outlook for the entire third quarter. However, the world's largest, Wal-Mart Stores Inc (WMT.N: Quote, Profile, Research), raised its profit outlook on improved margins and lower expenses, even though sales offered no upside surprise.

Prices for U.S. government bonds initially fell on the trade deficit and jobless claims data as traders saw less chance of future interest-rate cuts by the Federal Reserve. However, U.S. Treasury bond prices later rose slightly as U.S. stocks retreated from a sharp rally.

The blue-chip Dow Jones industrial average (.DJI: Quote, Profile, Research) fell 63.57 points, or 0.45 percent, to close at 14,015.12, while the tech-heavy Nasdaq (.IXIC: Quote, Profile, Research) slipped 39.41 points, or 1.40 percent, to end at 2,772.20, as a downbeat brokerage comment on Chinese Internet company Baidu.com Inc spooked investors. The Standard & Poor's 500 Index (.SPX: Quote, Profile, Research) declined 8.06 points, or 0.52 percent, to finish at 1,554.41.

Earlier in the day, both the Dow and the S&P 500 hit all-time highs, while the Nasdaq climbed it its highest level since January 2001.

BOOST TO GDP

The trade gap narrowed 2.4 percent to $57.6 billion in August as a weak U.S. dollar and stronger growth overseas gave a lift to exports, a Commerce Department report showed.

"If the September trade figure were to come in close to August, it would add 1 percent to Q3 (gross domestic product), bringing it to roughly 3 percent," said Keith Hembre, chief economist with FAF Advisors in Minneapolis.

U.S. imports fell slightly from the record set in July and would have dropped more -- cutting further into the trade gap -- if the price of imported oil had not hit an all-time high of $68.09 per barrel.

Oil prices have since risen further. A separate report from the Labor Department showed overall U.S. import prices rose a larger-than-expected 1 percent in September as the price of imported petroleum increased 5.4 percent.

Many economists are expecting a weak dollar to help give a lift to the U.S. trade sector and help buffer the economy from the big drop in housing activity.

The report on jobless claims from the Labor Department suggested the spillover to the rest of the economy remains limited, reinforcing the impression from a fairly robust monthly payrolls report last week.

Not only did the number of workers filing an initial claim for benefits fall last week, but the number who remained on the benefit rolls after claiming an initial week of aid hit its lowest level since June in the week ended September 22, the latest for which data is available.

"It looks as if companies are maintaining their labor forces, not reducing them, which is good news heading into the holiday shopping season," said Gary Thayer, chief economist at A.G. Edwards and Sons in St. Louis.