CVS Health beat Wall Street expectations for the second-quarter, helped by rising prescription sales, though a nearly $4 billion charge from one of the company’s businesses led to a loss.

The drugstore chain and pharmacy benefits manager said Wednesday that it has struggled to grow its long-term care business as much as it had expected after acquiring Omnicare in 2015. It cited lower occupancy rates in skilled nursing facilities and the financial struggles of its customers. Omnicare provides pharmacy services to nursing homes and other clients.

The company booked a charge of $3.9 billion in the quarter after a goodwill impairment test showed that the fair value of that business was lower than the carrying value.

That and some charges from a pending $69 billion acquisition of the health insurer Aetna led to a $2.56 billion loss in the quarter, compared with a $1.1 billion profit during the same period last year.

But adjusted earnings, which don’t count one-time items like charges, came in at $1.69 per share. Revenue rose 2 percent to about $46.7 billion.

Analysts predicted earnings of $1.61 per share on $46.32 billion in revenue, according to FactSet.

CVS said Wednesday that it now expects to earn between $6.98 and $7.08 per share this year, better than the per-share projections of between $6.87 and $7.08 that the company put out in May.

Analysts expect, on average, earnings of $6.97 per share.

CVS Health Corp., based in Woonsocket, Rhode Island, runs more than 9,800 retail locations and processes over a billion prescriptions annually as a pharmacy benefit manager.

Regulators are still reviewing the Aetna deal, but CVS Health said it expected to close that transaction either late in the third quarter or early in the fourth.

Company shares climbed a dollar to $66.45 in premarket trading.

© The Associated Press. All rights reserved.