Pharmacy benefits manager Caremark has agreed to pay $38.5 million in a settlement of claims that it was deceptive when it encouraged patients in Iowa and other states to switch prescription drugs under the guise of saving money.

Instead, Caremark kept rebates and discounts that it should have passed on to patients and employers, Pennsylvania Attorney General Tom Corbett said Thursday. The company also did not adequately explain to doctors how switching drugs would affect a patient’s costs, Corbett said.