NEW YORK—U.S. companies have retained strong profit margins through the pandemic because they have cut costs and passed along high prices to customers. The question is: How long can this go on? With inflation still strong, the ability for companies to keep margins at record levels is being closely watched by some investors and strategists as third-quarter earnings reports from S&P 500 companies are set to arrive next month. Much-stronger-than-expected earnings have been a key support for stocks this year even as the coronavirus pandemic has dragged on. The S&P 500 index is up about 17 percent for the year so far. Given the way companies have been handling costs, profit margins should edge higher in the near term, said Jonathan Golub, chief U.S. equity strategist and head of quantitative research at Credit Suisse Securities in New York. “Companies are doing a great job of managing costs in a difficult …