Procter & Gamble beat earnings expectations as higher prices helped offset lower demand for its products.