Stocks posted weekly gains Friday, while Federal Reserve Chair Janet Yellen put an exclamation point on the possibility of a rate hike this month.

"I think Janet Yellen has done a good job of walking the tightrope of preparing the market for this," said Ben Baier, senior portfolio manager at Bank of the West. "It would take something big to knock them off this rate hike."

While leaving just enough wiggle room in case conditions should change, the central bank leader said economic improvements of late will be a big part of the discussion at the March 14-15 Federal Open Market Committee meeting.

"With the Fed, we're going from red to green; there's no yellow," said Tom Siomades, head of Hartford Funds Investment Consulting Group. But "they haven't been very overt in terms of action. It's always been a wait-and see Fed, and that's what makes people nervous."

Dow, S&P and Nasdaq this week

Source: FactSet

Recently, a slew of top Fed officials indicated that tighter monetary policy may be coming soon.

Market expectations for a March rate hike have skyrocketed to 81 percent, according to the CME Group's FedWatch tool, on the back of hawkish rhetoric and solid economic data.

"With the odds so high in the market, I think they will raise rates," said Brent Schutte, chief investment strategist at Northwestern Mutual Wealth Management. "The market is giving the Fed the green light to raise."

The Dow Jones industrial average closed around breakeven, with Nike contributing the most losses and Goldman Sachs the most gains. The ended about 0.05 percent higher, with financials and health care leading advancers. The Nasdaq composite outperformed rising 0.1 percent.

Data released Friday included the IHS Markit sevices PMI, which hit a five-month low and the ISM nonmanufacturing index, which came in at 57.6 for February.

"It seems the market is willing to accept a rate hike if the data support it," said Quincy Krosby, market strategist at Prudential Financial. But "clearly, the market at this point is overextended."

"That doesn't mean it can't go higher. That said, there is more caution from institutional investors," she said.

Stocks have risen to record levels since the U.S. election and expectations of tax reform, deregulation and government spending have been at the crux it. The three major indexes posted their best day of 2017 on Wednesday, notching fresh record highs.

Stocks around the world, meanwhile, traded mostly lower Friday, but have posted solid gains year to date. The pan-European Stoxx 600 index declined 0.1 percent, while Japan's Nikkei 225 and South Korea's Kospi fell 0.49 percent and 1.14 percent, respectively.

"Although the stock market rally has been phenomenal this quarter, investors should remain vigilant as the bearish attributes for a selloff still linger in the background. The political risks in Europe, Brexit woes and ongoing Trump uncertainties could still trigger a wave of risk aversion," said Lukman Otunuga, research analyst at FXTM, in a note.

International traders and investors also paid close attention to the French elections. A poll conducted by Odoxa showed centrist Emmanuel Macron ahead of far-right candidate Marine Le Pen by 1 percentage point in the first round of the election. The election has been on investors' radars because Le Pen has said she would pull France out of the European Union if she won.

The spread between the French 10-year note yield and its German counterpart narrowed to about 60 basis points, or 0.6 percentage points. Early last week, the spread had widened to its highest level in about five years as investors dumped French debt in favor of German bonds.

In currencies, the U.S. dollar fell against a basket of currencies, with the euro near $1.06 and the yen around 114.04.

The Mexican peso soared against the greenback after Commerce Secretary Wilbur Ross told CNBC that a good trade deal between the U.S. and Mexico can help the beaten-down currency recover.