Stocks Log Weekly Gain, Dow Just Shy of 13,000

Stocks closed mixed in thin trading Friday ahead of the three-day holiday weekend, but all major averages logged robust gains for the week following some positive economic news and amid optimism that Greece will soon find a solution to its debt crisis.

The Dow Jones Industrial Average rose 45.79 points, or 0.35 percent, to close at 12,949.87, just shy of the psychologically-important 13,000 mark. DuPont and Intel , led the blue-chip gainers.

The S&P 500 added 3.19 points, or 0.23 percent, to end at 1,361.23. Meanwhile, the Nasdaq pulled back 8.07 points, or 0.27 percent, to finish at 2,951.78 after several days of gains.

The CBOE Volatility Index, widely considered the best gauge of fear in the market, ended below 18.

For the week, the Dow soared 1.16 percent, the S&P rallied 1.38 percent and the Nasdaq jumped 1.65 percent. The S&P and the Nasdaq have logged their sixth week of gains in seven. Hewlett-Packard led the Dow gainers for the week, while Kraft Foods slumped.

All 10 S&P sectors finished higher for the week, led by energy.

"No one wants to risk staying short if there is really a deal in Greece over the weekend," said Brian Battle, vice president of trading at Performance Trust Capital Partners. "But the sustainability of the rally is another question."

Optimism in Europe grew after German officials gave up plans to pressure Greece by withholding part of the bailout. European shares ended higher as investors bet that Greece would sign a deal to secure a second bailout by Monday, avoiding a messy default.

Meanwhile, German president Christian Wulff resigned amid a scandal over political favors. The move comes as a blow to chancellor Angela Merkel who had personally selected Wulff for the post. Merkel also postponed a trip to Rome to meet Italian Prime Minister Mario Monti.

“Friday before a three-day weekend has a natural prejudice the upside,” said Art Cashin, director of floor operations at UBS Financial Services. “Interestingly, the Friday before the Presidents’ day is the weakest of the lot.”

The stock market will be closed next Monday for Presidents' day.

Among earnings, Campbell Soup gained after the soup maker posted better-than-expected quarterly earnings.

Heinz also rose after the maker of Ketchup and other condiments reported earnings that beat estimates, thanks to growth in emerging markets.

But General Mills slumped after the cereal maker said it is lowering is 2012 earnings forecast, citing weaker U.S. sales volumes in the last two months.

Gilead Sciences tanked almost 15 percent after the drugmaker said some patients treated with its experimental hepatitis C drug, experienced a relapseof the infection in an ongoing study. Meanwhile, rival Vertex shares rallied.

Johnson & Johnson eked out a gain after the pharmaceutical giant said it is recalling about 574,000 bottles of its infant Tylenol after dosage issues.

Meanwhile, Vivus soared amid increasing hopes that the FDA could approve the drugmaker's weight-loss pill.

Meanwhile, 3M said it plans to contribute up to $1 billion of cash to global pension and post-retirement plans this year.

Shares of Madison Square rose following reports that the firm has settled a dispute with Time Warner Cable , according to the New York Times.

Baidu sagged after Morgan Stanley said it expects the Chinese Internet giant earnings growth rate to slow down in 2012 due to "macro overhangs."

On the IPO front, online review site Yelp said it expects to sell 7.15 million sharesin its initial public offering at between $12 and $14 each.

On the economic front, consumer prices climbed in January as gasoline prices gained, according to the Labor Department, logging its biggest gain in four months.

Also on the economic front, leading indicators rose in January, according to the Conference Board, climbing to a 3-1/2 year high.

—Follow JeeYeon Park on Twitter: @JeeYeonParkCNBC

On Tap Next Week:

MONDAY: Presidents' Day—Markets Closed
TUESDAY: 2-yr note auction; Earnings from Home Depot, Kraft, Wal-Mart, Macy's, RadioShack, Saks, Chesapeake Energy, Dell
WEDNESDAY: Weekly mortgage apps, existing home sales, 5-yr note auction; Earnings from Dollar Tree, TJX, Toll Brothers, Hewlett-Packard
THURSDAY: Jobless claims, FHFA home price index, oil inventories, 7-yr note auction, Apple shareholders meeting; Earnings from Hormel, Kohl's Target, AIG, Gap
FRIDAY: Consumer sentiment, new home sales; Earnings from JCPenney

More From