NEW YORK - The S&P 500 and Nasdaq finished in the red while Treasury yields rose as investors digested signs of cooling U.S. inflation and hopes the Federal Reserve could slow interest rate hikes against warnings that the battle with rising prices was far from over.

Thursday's data showed U.S. producer prices (PPI) unexpectedly fell in July amid a drop in the cost of energy products. This followed Wednesday's surprise news that consumer prices (CPI) were unchanged in July due to a drop in gasoline prices.

U.S. Treasury yields rallied after dropping sharply earlier.

Two straight days of slower inflation data gave investors some hope that soaring prices were finally "peaking and heading in the right direction," said Joe Saluzzi, co-manager of trading at Themis Trading in Chatham, New Jersey.

But Saluzzi cautioned that this was a "one month data point."

"You'd still like to see a trend next month and see it's not necessarily just energy. You want to see other prices coming down. It's still early in the game," Saluzzi added.

After adding more than 2% on Wednesday and rising more than 1% to a three-month high earlier on Thursday, the S&P turned red in afternoon trading and Nasdaq turned negative.

"It was a better CPI print (Wednesday) than expected and a better PPI print (Thursday) morning than forecasted by analysts. So it fit that theme, that peak inflation has occurred as energy continues to decline," said George Catrambone, head of Americas trading at DWS Group. "But I would be concerned about a head fake."

The Dow Jones Industrial Average rose 27.16 points, or 0.08%, to 33,336.67, the S&P 500 lost 2.97 points, or 0.07%, to 4,207.27 and the Nasdaq Composite dropped 74.89 points, or 0.58%, to 12,779.91.

The pan-European STOXX 600 index closed up 0.06% and MSCI's gauge of stocks across the globe finished up 0.07%.

Robert Phipps, a director at Per Stirling Capital Management in Austin, Texas, expects the Fed to be cautious about slowing the tightening cycle until inflation shows more improvement.

"The Fed's learned their lesson. They're not going to take their foot off the brakes until it's obvious to everybody that inflation is returning to their 2% target," Phipps said.

San Francisco Fed President Mary Daly, in an interview with the Financial Times, earlier said that it was far too early for the central bank to declare victory in its fight against inflation and that a half-percentage point rate rise in September was her baseline.

Daly's comments followed similar cautions from Minneapolis Federal Reserve Bank President Neel Kashkari and Chicago Fed President Charles Evans on Wednesday.

The dollar, which fell 1% on Wednesday on the prospect of a more dovish Fed, pared losses on Thursday after likely gaining some support from the Fed officials' commentary.

In Treasuries, 10-year note yields hit a more than two-week high as investors in that market bet that the Fed would press on with rate hikes since inflation, while showing signs of abating, remained high.

"Even if they're seeing slowing inflation and a slowing of the economy, they will still hike rates. Why? Because inflation still has an 8% handle on it. It's still far too high," said Padhraic Garvey, regional head of research, Americas at ING.

Benchmark 10-year notes last fell 29/32 in price to yield 2.8839%, from 2.781% late on Wednesday. The 30-year bond last fell 78/32 in price to yield 3.1716%, from 3.042%.

The dollar index fell 0.114%, with the euro up 0.24% to $1.0322.

The Japanese yen weakened 0.09% versus the greenback at 133.04 per dollar, while Sterling was last trading at $1.2196, down 0.24% on the day.

In commodities, oil settled higher after the International Energy Agency raised its oil demand growth forecast for 2022 as soaring natural gas prices lead some consumers to switch to oil.

U.S. crude settled up 2.6% at $94.34 per barrel and Brent finished at $99.60, up 2.3% for the day.

Spot gold dropped 0.3% to $1,787.61 an ounce.

(Additional reporting by Herbert Lash, Karen Brettell, Huw Jones, Sujata Rao, Stella Qiu and Alun John; Editing by Elaine Hardcastle, Will Dunham, David Holmes and John Stonestreet)