Stocks posted small gains Thursday after Federal Reserve chairman Ben Bernanke said the central bank will stick to its efforts to spur the economy.

In a speech at the National Press Club, Bernanke said that the Fed expects the economy to improve this year and inflation to remain low despite the jump in commodity prices.

"Chairman Bernanke basically indicated in his speech that he considers unemployment to be the bigger problem than inflation and that the Fed will continue to focus on that," said Doug Roberts, chief market strategist at Channel Capital Research.

The Federal Reserve is on track to buy $600 billion in bonds, a tactic known as quantitative easing, aimed at spurring lending and making stock ownership more attractive. Some economists had worried that the Fed could end its bond purchases earlier than anticipated.

Stocks had fallen for the most of the day as concerns over violent protests in Egypt weighed against better-than-expected economic news in the U.S.

Clashes continued in Egypt between pro- and anti-government demonstrators, leaving some analysts worried about the stability of the Middle East and the unrest's impact on oil-rich countries throughout the region, such as Saudi Arabia.

"That's the fear," said Peter Cardillo, chief market economist at Avalon Partners.

But better-than-expected January sales figures sent shares in retail companies higher. Consumer-discretionary companies in the Standard and Poor's 500-stock index gained 1.2 percent after national chains reported that sales were nearly double what analysts had forecast despite heavy snowstorms in much of the nation.

Shares in the consumer-discretionary companies were the best performers among the 10 company groups that make up the S&P index. Industrials companies were the only group to fall.

Costco Wholesale Corp., Nordstrom Inc. and Gap Inc. all gained more than 4 percent.

The S&P 500 — the benchmark for most U.S. mutual funds — gained 3.07 points, or 0.2 percent, to close at 1,307.10. The Dow Jones industrial average rose 20.29 points, or 0.2 percent, to 12,062.26. The Nasdaq composite rose 4.32 points, or 0.2 percent, to 2,753.88.

Rising shares outpaced falling ones by a small margin on the New York Stock Exchange. Consolidated trading volume came to 4.5 billion shares.

Among the positive economic reports, the Labor Department said Thursday that fewer people applied for unemployment benefits last week. A separate report showed that worker productivity in December rose by its largest amount since 2002. Economists say many employers have reached the limit in terms of how much work they can squeeze from their employees.

The Commerce Department said that factory orders rose in December, the fifth gain in six months.

Drugmaker Merck & Co. fell 2.7 percent after it issued a full-year profit forecast that was lower than analysts had expected. The company was the worst performer among the 30 stocks that make up the Dow average.

Warehouse club operator BJ's Wholesale Club Inc. rose 12 percent after it said it is considering selling itself after months of buyout speculation.

The better economic news pushed Treasury prices lower. The yield on the 10-year Treasury note rose to 3.55 percent from 3.48 percent late Wednesday. Bond prices move in the opposite direction from their yields.