There are plenty of good reasons to consider putting more of your hard-earned money into companies that offer necessary goods, generate stable revenue, and are consistently profitable. Inflation is reining in consumer spending, meaning those goods that are must-haves tend to be prioritized. Furthermore, with interest rates rising, speculative growth stocks will be hit harder than stocks of more established corporations.

With that in mind, let's look at two relatively safe options in the stock market right now: Bristol Myers Squibb (BMY -0.30%) and Merck & Co. (MRK -0.05%). Both of these drugmakers have outperformed the broader market this year. Here's why.

BMY Chart

BMY data by YCharts.

1. Bristol Myers Squibb

Bristol Myers is a pharmaceutical company that primarily (although not exclusively) focuses on oncology. Some of its best-selling medicines include cancer treatments Pomalyst, Revlimid, Opdivo, Sprycel, and Yervoy. Its lineup also features anticoagulant Eliquis and rheumatoid arthritis therapy Orencia. No patient wants to cut back on essential medications, especially not those that treat such serious illnesses as cancer or rheumatoid arthritis.

Bristol Myers is going through a bit of a transition. This year the company started facing generic competition for Revlimid, one of its top-selling drugs, in the U.S. With sales of Revlimid declining, Bristol Myers' revenue growth has been a bit less impressive. In the second quarter, the company's top line jumped by 2% year over year to $11.9 billion.

In fairness, Bristol Myers' revenue jumped by a more respectable 5% year over year when adjusting for foreign exchange rate fluctuations. Still, the drugmaker needs new products to replace Revlimid and other older therapies. Thankfully, Bristol Myers has already secured several approvals for promising new products this year.

Earlier this month, Bristol Myers earned the green light in the U.S. for plaque psoriasis medicine Sotyktu. In March, the company's cancer drug Opdualag got the nod. And in April, Camzyos, which targets a heart condition called obstructive cardiomyopathy, also won approval. That's in addition to the label expansions the company keeps earning for some of its legacy products such as Opdivo.

The new products should help offset the losses Bristol Myers will incur from older ones. And there's more where those came from, since the company still has dozens of ongoing programs. Bristol Myers' ability to generate somewhat stable revenue and profits and the fact that it offers goods that its customers can hardly do without partly explain why it has outperformed the market this year.

But there's also the fact that the valuation remains reasonably attractive, with a forward price-to-earnings (P/E) ratio of 9.4 -- compared to the pharmaceutical industry's forward P/E of 12.9. It's just one more reason why Bristol Myers looks like a safe haven in today's challenging market.

2. Merck & Co.

Merck is yet another drugmaker with a strong presence in the oncology market. The company's key product is Keytruda, which has earned dozens of approvals in the U.S. alone and continues to spearhead revenue growth. Merck has other products, including HPV vaccines Gardasil and Gardasil 9, cancer medicine Lynparza (the rights to which it shares with AstraZeneca), and its animal health unit.

However, Keytruda plays a special role in Merck's portfolio. During the second quarter, sales of the cancer drug jumped by 26% year over year to $5.3 billion, accounting for about 36% of the company's total sales. Perhaps this lack of diversification can hurt Merck, but Keytruda won't lose patent protection until 2028, meaning it still has plenty of time to grow its revenue before facing generic competition.

Back in June, Merck said Keytruda had reached an important milestone of serving 1 million commercial patients. The medicine was first approved in 2014, but management is confident that it can double its total number of commercial patients by 2024. Also, Merck is developing a subcutaneous formulation of its crown jewel.

Elsewhere, Merck is looking to diversify its portfolio. The company is working on several new programs which, together with Keytruda, could help deliver more than 80 new oncology approvals by 2028. Oncology remains one of the largest and fastest-growing therapeutic areas within the pharmaceutical industry.

Merck's longstanding expertise in this field and its ability to innovate should help it deliver newer groundbreaking products. The drugmaker will also likely benefit from the expanding animal health industry. And Merck looks reasonably valued, too; its forward P/E is just 11.7 as of this writing. This steady, blue-chip company would be a fine addition to almost any portfolio for this year and beyond.