On Tuesday morning, Macy's (NYSE:M) and Dillard's (NYSE:DDS) -- two of the leading mid-price department store operators -- reported strong results for the final quarter of fiscal 2017. This marked a big trend change from the persistent sales declines they had suffered for most of the past three years.

Management at Macy's and Dillard's also struck an optimistic tone about 2018. If retail sales trends remain strong, shares of both department store companies could continue their recent rally during the remainder of 2018.

A return to comp sales growth

Until recently, sales trends seemed to be spiraling out of control at both Macy's and Dillard's. Macy's entered the fourth quarter having not posted an increase in comparable-store sales since the fourth quarter of fiscal 2014. Dillard's most recent comp sales gain had been in the second quarter of fiscal 2015.

However, both retailers turned things around last quarter. Macy's posted a 1.4% comp sales gain, following up a strong holiday season with an even better January performance. This was a big improvement over its 3.6% comp sales decrease for the first three quarters of the fiscal year.

The exterior of the Macy's Manhattan flagship store

Macy's broke a streak of 11 consecutive quarterly comp sales slumps in Q4. Image source: Macy's.

Dillard's delivered an even better performance. Comp sales rose 3% year over year in the fourth quarter, compared to a 2% dip in the first three quarters of fiscal 2017.

Earnings soar, as you'd expect

Most retailers have high operating leverage, meaning that small changes in sales can have a much larger impact on profitability. After all, many of the costs of operating a store don't change much if more customers come through the door. Additionally, strong sales trends tend to boost gross margin, as fewer items need to be cleared out with deep discounts.

As a result, it's not surprising that Macy's and Dillard's both posted very strong earnings results. Macy's reported that earnings per share soared to $2.82 from $2.02 a year earlier. This was $0.08 above the high end of Macy's updated guidance. Analysts had expected EPS of $2.71.

These EPS results included a $0.48 gain from the sale of the Union Square men's store in San Francisco and a $0.07 benefit from the lower tax rate that went into effect in January. Excluding those factors, Macy's still achieved double-digit EPS growth. (It's worth noting that some of this EPS growth stems from there being an extra week in the fourth fiscal quarter this year.)

Dillard's achieved even more impressive EPS growth last quarter. Adjusted EPS soared to $2.82 from $1.85 a year earlier, thanks to a roughly pre-tax margin improvement of 1 percentage point. This blew past the average analyst estimate of $1.77.

The outlook is good

Both companies are optimistic that the good times will continue in 2018. Macy's expects comp sales to rise as much as 1%, while full-year EPS will reach $3.55-$3.75, as a reduced tax rate of 23.25% will offset growth investments and lower asset sale gains. (Full-year adjusted EPS was $3.77 for fiscal 2017.)

As usual, Dillard's didn't provide quantitative guidance or hold an earnings call. CEO William Dillard II said simply, "We are working to keep this momentum into 2018."

Dillard's stock soared 17% on Thursday, reaching a new 52-week high, as investors cheered its blowout earnings report. Macy's stock traded up by double digits in the morning, but by the end of the day, its gain had shrunk to 3.5%.

Macy's and Dillard's stock chart

Macy's and Dillard's stock performance. Data by YCharts.

However, Macy's looks like a better bet going forward. First, Macy's ended last quarter with inventory down 4% year over year, compared to up 4% at Dillard's. That puts Macy's in a better position to react to demand trends in the next quarter or two.

Furthermore, Macy's had an adjusted pre-tax margin of 5% last year -- excluding asset sale gains -- compared to approximately 3.3% at Dillard's. Including asset sale gains, Macy's has an even bigger margin advantage over its smaller rival.

Finally, Macy's is reinvesting about 4% of its revenue in capital projects, whereas capex averages around 2% of revenue at Dillard's. In the long run, these investments will give Macy's a better shot at growing (or at least maintaining) its revenue than Dillard's.

This article represents the opinion of the writer, who may disagree with the “official” recommendation position of a Motley Fool premium advisory service. We’re motley! Questioning an investing thesis -- even one of our own -- helps us all think critically about investing and make decisions that help us become smarter, happier, and richer.