First-quarter gross domestic product was 3.2% , the Commerce Department said on Friday, topping the consensus economist estimate of 2.5%, according to Dow Jones. An increase in exports drove the better-than-expected number.

The S&P 500 climbed 0.5% to 2,939.88, an all-time closing high. The tech-heavy Nasdaq ended the day up 0.3% at 8,146.40. The Dow Jones Industrial Average rose 81.25 points to 26,543.33 and closed 1.5% below its all-time high.

The and Nasdaq Composite closed at record highs on Friday as better-than-expected economic data offset a mixed batch of corporate earnings.

Traders and financial professionals work ahead of the closing bell on the floor of the New York Stock Exchange.

"The economic expansion will set new records for longevity in July and it looks like there is no stopping this economy," said Chris Rupkey, chief financial economist at MUFG, in a note. "We had all but given up on the first quarter with the Federal government shutdown ending January 25, frigid winter weather conditions shutting down manufacturing production, and the fears of a world growth slowdown."

"So far the fears are unfounded," Rupkey said.

The major indexes hovered around the flatline for most of the session as companies like Exxon Mobil and Intel delivered quarterly reports that disappointed investors.

Dow member Exxon fell more than 2% after the company's results were dragged down by poor performances in its refining and chemicals businesses. Intel, another Dow component, fell 9% after the company issued light revenue guidance for the year. The stock also posted its biggest one-day drop since 2016.

"The burden of proof is fairly high," said Eric Wiegand, senior portfolio manager at U.S. Bank Wealth Management. "Investors' appetite for companies that either disappoint or offer lower guidance on a go-forward basis tends to be met with a pretty sharp reaction."

Those results overshadowed stronger-than-expected numbers from companies like Amazon and Ford Motor.

Amazon shares closed 2.5% higher after results topped expectations on Thursday and Wall Street analysts trumpeted its announced push to one-day delivery for Prime members.

Ford Motor, meanwhile, jumped 10.7% — posting its biggest gain since 2009 — after issuing better-than-forecast quarterly numbers, which were driven by strong truck and SUV sales in North America.

Other companies that reported between Thursday afternoon and Friday morning include, Mattel, Starbucks and American Airlines.

The S&P 500 and Nasdaq posted solid gains this week after more than 140 companies released their quarterly reports. The two indexes gained 1.2% and 1.9%, respectively. The Dow, meanwhile, posted a slight weekly loss.

Michael Geraghty, equity strategist at Cornerstone Capital Group, said investors should keep riding stocks higher as downside risks are limited.

"I don't think it's a time to be making significant additions to equities, but at the same time there is not a lot of downside risk," he said. "Net net, we're advising our clients to stick with their equity positions and, if stock prices decline from current levels, that may be a buying opportunity."

—CNBC's Sam Meredith contributed to this report.