The dip in financial markets has led many investors to flock to stocks that are seen as high-yielding safe havens. This could partly explain why the pharma stock Merck (MRK 0.44%) has rallied 21% year to date while the S&P 500 index has dropped 18% during that time.

And even with the stock's massive gains thus far this year, Merck still looks like a buy. Let's dig into its fundamentals and valuation to learn why.

The company consistently surpasses expectations

Last month, Merck reported results for the first quarter, ended March 31. And the company once again topped analysts' estimates.

For the quarter, Merck recorded $15.9 billion in net sales, which represented a 49.6% increase over the year-ago period. This easily outperformed the analyst consensus of $14.6 billion. The first quarter marked the eighth quarter out of the last 10 that the company beat the average analyst forecast for net sales.

Merck's antiviral COVID-19 treatment, Lagevrio, generated $3.2 billion in sales, accounting for 61.6% of net sales growth for the quarter. But even excluding Lagevrio from its financial results, the company still grew net sales by 19.1% in the first quarter.

This was driven by robust net sales growth for Merck's top-selling cancer drug, Keytruda, and its Gardasil human papillomavirus (HPV) vaccine franchise. Keytruda's continued expansion of cancer indications led its net sales to surge 23.3% higher year over year to $4.8 billion in the first quarter. And growing demand for HPV vaccines sent Gardasil net sales 59.2% higher to $1.4 billion for the quarter.

Meanwhile, the company produced $2.14 in adjusted diluted earnings per share (EPS) in the quarter, 84.5% higher than the year-ago period. This blew the average analyst prediction of $1.83 out of the water.

So how did Merck match or outdo the analyst earnings consensus for the eighth quarter out of the past 10 quarters?

The company's higher net sales base and improved operating efficiency led its adjusted net margin to soar 640 basis points year over year to 34.1% in the quarter. Along with a 0.2% reduction in its average diluted shares outstanding, this explains the huge jump in earnings.

Merck's growth will likely slow considerably from its red-hot pace of the first quarter. That's because its COVID-19 antiviral drug, Lagevrio, is only a temporary boost to revenue and profits and will fade over time. But with a late-stage pipeline of 106 projects, analysts are still expecting a strong 11.6% annual earnings growth for the next five years.

A doctor and patient converse at an appointment.

Image source: Getty Images.

Solid dividend growth lies ahead

Merck's promising earnings-growth prospects aren't all. The seemingly unstoppable company also offers investors a safe, market-beating 3% dividend yield.

Its dividend payout ratio is expected to be 37.6% in 2022. This allows the company to keep enough funds for acquisitions, share repurchases, and debt reduction to drive adjusted diluted EPS upward.

This is why I expect annual dividend raises in the high-single-digit range for the next few years. Coupled with a 3% yield, this makes Merck an interesting choice for income investors.

The stock isn't getting its due respect

Merck is clearly a fundamentally healthy business. But that doesn't appear to be fully reflected in the current $93 share price.

It trades at a forward price-to-earnings (P/E) ratio of 12.7, which is just below the pharmaceutical industry average of 13.1. And this is despite the fact that Merck's 11.6% annual earnings growth outlook is far higher than the industry average of 7%.