Energy companies led stocks modestly higher Wednesday, nudging the Nasdaq composite to its fifth record-high close in a row.

But health care stocks, especially drugmakers, fell after President-elect Donald Trump spoke about the need for the government to stem drug costs by creating new bidding procedures. Pharmaceutical company Endo International led the decliners in the Standard & Poor's 500 index, sliding 8.5 percent.

The stock market spent much of the day wavering between small gains and losses as investors sized up outlooks from several companies ahead of the latest batch of corporate earnings reports.

"The heavy load comes in the coming weeks," said Tim Dreiling, regional investment director for U.S. Bank's Private Client Reserve. "There's a little bit of a wait-and-see on what those earnings numbers look like."

During a news conference Wednesday, Trump said the government has to create new bidding procedures for the pharmaceutical industry "because they're getting away with murder." The remarks sent health care stocks broadly lower, particularly pharmaceutical companies. At one point, drugmakers and one prescription drug distributor accounted for the nine biggest losers in the S&P 500.

Not all drugmakers had a bad day.

Merck rose 2.9 percent after news that the Food and Drug Administration will do a quick review of one of the company's drugs for its potential to treat a type of lung cancer.

"As we look into 2017, we still expect equities are going to be able to grind higher, because we still have enough of an economic push to do that," Dreiling said. "But a move up in equities is going to have to come from earnings, otherwise, these valuations ... look pretty stretched, pretty rich at these levels."