The process of investing can be described as simple, but not easy. An investor can accrue outsize gains simply by buying index funds over time, for example, or by building a portfolio packed with high-quality businesses and holding on for many decades.

The hard part comes when trying to identify those superb businesses beforehand. It's also a challenge for many investors to hold stocks through the ups and downs of intense market volatility.

It can help your resolve to have a good understanding of the business in question. You're also more likely to be patient with a stock when it returns lots of cash to you through dividends or share buybacks. So let's look at some of these stocks that can anchor your portfolio for many decades. Read on for some good reasons to buy Procter & Gamble (PG -0.78%) and Microsoft (MSFT 1.82%).

1. Procter & Gamble

There are several metrics an investor can point to that suggest Procter & Gamble is a uniquely strong business. The consumer-staples giant has been paying a dividend for more than a century, for example, and has been raising that payout for 67 consecutive years. There's also the fact that P&G dominates so many niches of products that millions of people use daily. These include diapers, paper towels, and laundry detergent, to name a few .

P&G routinely posts much higher profitability than its peers as well. Operating profit margin has held up above 20% of sales in recent years, compared with Kimberly-Clark (KMB -0.87%) and its 14% rate. That gap partly reflects P&G's prime market position as a leader in its industry. It also reflects the company's scale and the affinity that millions of consumers have to brands such as Tide and Bounty.

Shares look reasonably priced today, too, after having sat out of the 2023 stock rally through early September.

2. Microsoft

Even a relatively small investment in Microsoft could lift a portfolio over time, if you believe in the long-term potential of tech niches such as cloud services, cybersecurity, and artificial intelligence (AI). Sure, the software giant's not going to be putting up growth numbers the way it did 20 or 30 years ago. But sales still expanded at a double-digit rate in the most recent quarter, beating expectations. Those gains occurred despite falling demand in niches such as tech device hardware, illustrating the power of Microsoft's diverse portfolio.

The company generates impressive earnings and cash flow, having boosted operating profit by a blazing 21% this past quarter to $24 billion. That translates to a profit margin of more than 40% of sales, making Microsoft one of the most efficient businesses around .

The biggest risk to buying this stock is paying too high of a price. With shares valued at nearly 12 times annual sales, that's a real concern today. For context, you can own Amazon, which is admittedly much less profitable, for closer to 3 times sales.

Yet a holding period that stretches into decades can lessen the risk around valuation swings. You can take your time building a position in Microsoft as well, by buying in thirds or by waiting for a drop in the wider market before purchasing.

Still, Microsoft has earned a premium valuation by building a robust portfolio of tech services that can grow through a wide range of selling conditions. These assets should help support excellent returns for shareholders who keep this stock in their portfolios for an investing lifetime.