Walgreens (WAG) revealed on Friday better-than-expected fourth-quarter earnings but disappointing sales as demand for prescriptions and store traffic fell.

The Deerfield, Ill.-based pharmacy chain posted net earnings of $353 million, or 39 cents a share, compared with a year-earlier $792 million, or 87 cents.

Excluding one-time items such as the impact of its $6.7 billion Alliance Boots purchase, Walgreens earned 63 cents, topping average analyst estimates of 56 cents in a Thomson Reuters poll.

Revenue for the three months ended Aug. 31 was $17.07 billion, down from $17.9 billion a year ago, missing the Street’s view of $17.2 billion.

Same-store customer traffic fell 3.2%, while prescription sales shrunk by 12.8% at stores open longer than a year. The switch by name-brand drugs to less expensive generics hurt sales by 3.7%.

“This was a challenging, but very important year for Walgreens, and we finished with a tough quarter,” CEO Greg Wasson said in a statement. “While we controlled costs and generated strong cash flow in the fourth quarter, our performance also reflected a strategic shift in promotional spending, a continued economically challenged consumer, and the impact from Express Scripts.”

The company has been struggling to make up for the revenue lost when it was dropped by Express Scripts in January over a dispute, leading customers to bring their prescriptions elsewhere to be filled. However, the two agreed to a new multi-year deal this summer.

“Entering the new fiscal year, we believe we are positioned for growth,” Wasson said.

Shares of Walgreens touched a 52-week high of $36.90 before retreating with the broader market on Friday. In recent trade its shares slumped less than 1% to $36.37.

Follow Jennifer Booton on Twitter at @Jbooton