Enrollment fell about 2.2 percent to 39.5 million members at the end of the quarter, hit by a decline in the number of people signing up for Medicaid as well as for its Obamacare plans.

Shares of the company rose about 1 percent to $248.24 in late morning trade.

Jefferies analyst David Windley said a combination of membership declines in the commercial business and lower guidance for members probably weighed on the stock.

The company has reduced its footprint in Obamacare markets, but Cantor Fitzgerald analysts said the decline in Obamcare membership in the quarter was seasonally normal and the reduction probably helped it to lower patient costs.

Anthem Chief Executive Officer Gail Boudreaux said the health insurer was not looking to "rescale" the Obamcare business, but was pleased with the performance this year.

"As we go into 2019, while no decisions are final yet, we are assessing that. I think you'll see some county expansions," Boudreaux said on a conference call with analysts.

The company's tight control over patient costs in the quarter improved its benefit expense ratio to 83.4 percent from 86.1 percent in the year-ago period. The figure is widely watched in the sector because it measures an insurer's expenses on claims against the premiums it earns.

Last week, larger rival UnitedHealth Group reported a benefit expense ratio that missed analysts' estimates, overshadowing better-than-expected earnings.

In contrast to the debates around UnitedHealth and Centene Corp earnings, Anthem's results is a cleaner benefit expense ratio-driven beat and raise that still includes conservatism for the second half of the year, Evercore ISI analyst Michael Newshel said in a note.

Net income rose 23 percent to $1.05 billion, or $3.98 per share, in the second quarter ended June 30.

Excluding items, the company earned $4.25 per share, ahead of analysts' average estimate of $4.16, according to Thomson Reuters I/B/E/S.

Total revenue rose 2.4 percent to $22.94 billion. Operating revenue was $22.71 billion, compared with the analysts' estimate of $22.69 billion.

The company also raised its profit forecast and now expects 2018 adjusted earnings to be greater than $15.40 per share, up from its previous estimate of earnings of greater than $15.30 per share.

(Reporting by Ankur Banerjee and Tamara Mathias in Bengaluru; Editing by Bernard Orr)