The great thing about investing in healthcare companies is that the basic services they provide aren't going out of style anytime soon. But that only means the sector as a whole will likely continue thriving -- it says nothing at all about individual companies.

That's why, when investing in healthcare companies -- as in any other industry -- it helps to pick those players that can protect their share of the market through competitive edges. Two healthcare giants capable of doing that are HCA Healthcare (HCA -0.13%) and Veeva Systems (VEEV -0.29%).

Let's see why both of these stocks are worth buying.

HCA Chart
Data by YCharts.

1. HCA Healthcare

Let's start with the bad news with this hospital chain. At the pandemic's peak, patient traffic decreased in hospitals, leading to lower revenue for the company. With the rise of the omicron variant, HCA Healthcare is facing this risk again. We don't know how bad things will be, so it may be too early to panic. But a surge in COVID-19 cases, coupled with more government-imposed nonpharmaceutical interventions (such as lockdown orders and business closures) to contain the spread of the disease, present a real threat to HCA Healthcare. 

Now for the good news: These theoretical developments should only impact HCA Healthcare in the near term. For investors focused on the long term, it isn't worth stressing about in the least. For one, HCA Healthcare has managed to recover from last year's slump. During the third quarter, the company's revenue of$15.6 billion increased by 14.8% year over year.

HCA Healthcare's net income improved to $2.3 billion, up from the $668 million recorded during the year-ago period. However, the company's bottom line was significantly impacted by nonbusiness factors. It's best to compare HCA Healthcare's adjusted earnings before interest, taxes, depreciation, and amortization (EBITDA), which grew by 57% year over year to $3.2 billion.

Patient in a wheelchair surrounded by physicians.

Image source: Getty Images.

Now let's turn to HCA Healthcare's greatest competitive advantage, which is arguably is its sheer size: It is one of the largest hospital chains in the nation. The company's network in the U.S. boasts 178 acute care hospitals, which are primarily located in Texas and Florida. In 2020, 49% of its revenue came from its facilities in these two states. In addition, the company also owns surgery centers, psychiatric hospitals, rehabilitation hospitals, and endoscopy centers.

HCA Healthcare's size and the breadth of its services allow it to attract an increasing number of customers in the healthcare industry, including individual patients and large-scale payers (insurance companies and government-sponsored healthcare programs). Between 2013 and 2020, HCA Healthcare's market share increased from 23% to 27%. And the company is well-positioned to continue making gains. 

HCA Healthcare recently announced its intention to build three new hospitals in the sunshine state, where it already owns 47. Initiatives like these will allow the company to remain one of the leaders in this space for a while. Lastly, HCA Healthcare seems somewhat reasonably valued -- with a forward price-to-earnings ratio (P/E) of 12.3 -- compared to an average forward P/E of 12.6 for companies in this sector.

That makes it a great time to add shares of this healthcare giant to your portfolio. 

2. Veeva Systems 

Veeva Systems is a software-as-a-service (SaaS) company that focuses on the life sciences industry. There are multiple potential sources of moats for SaaS companies. One of the most powerful is undoubtedly high switching costs; deciding to jump ship from one SaaS provider to another can be a very expensive and time-consuming proposition. This certainly applies to Veeva Systems' clients. 

For instance, many drugmakers depend on Veeva Systems' suite of products to manage clinical compounds from the early stages of development to the time they hit the market -- not to mention the myriads of regulatory hoops they have to jump through in between. The slightest disruption in this process, which can arise as a result of transporting all the data involved from one database to another, can cost millions in additional expenses. 

That's why Veeva Systems doesn't have to worry about losing customers. In fact, the company routinely adds new ones. During the company's fiscal year 2021, which ended on Jan. 31, 2021, it recorded a retention rate of 124%, meaning customers expanded their use of Veeva's services. Before turning to Veeva Systems' long-term opportunities, though, let's look at one major issue with the company: valuation. It currently trades at a forward P/E of 67.7, which is high by almost any metric. Veeva Systems' shares are likely to be volatile in the near term as a result. 

The company's stock recently dropped after it released its financial results for its third quarter of 2022, which ended on Oct. 31, 2021. That was despite the fact that Veeva Systems' revenue of $476 million -- and its non-GAAP net income of $158.2 million -- both increased by 26% year over year, and both came in ahead of analyst estimates. Even factoring in this valuation-related caveat, though, I think Veeva Systems is an excellent stock to buy and hold.

The company sees a $13 billion total addressable market in the life sciences industry. It expects $1.8 billion in revenue for its current fiscal year. Of course, given that the healthcare sector it serves is valued at $2.2 trillion -- and growing -- there will be even more opportunities for the company in the future. Veeva Systems will not capture the entire market it is looking to address, but even a fraction of it would be a significant win for the company.

That's before we add that Veeva Systems is currently expanding into the cosmetic, consumer goods, and chemicals sectors. These combined tailwinds, coupled with Veeva Systems' already strong position, make its stock a buy, despite its sky-high valuation metrics.