A late wave of buying left stocks modestly higher on Wall Street after a day of bobbing between small gains and losses.

The gains Wednesday left major U.S. indexes slightly closer to the record high closes they reached in July. Health care and communications companies did the most to pull the market higher.

On Wednesday:

The S&P 500 rose 8.53 points, or 0.3%, to 3,004.52.

The Dow Jones Industrial Average gained 45.85 points, or 0.2%, to 26,833.95.

The Nasdaq composite added 15.50 points, or 0.2%, to 8,119.79.

The Russell 2000 index of smaller companies picked up 1.99 points, or 0.1%, to 1,552.86.

For the week:

The S&P 500 is up 18.32 points, or 0.6%.

The Dow is up 63.75 points, or 0.2%.

The Nasdaq is up 30.25 points, or 0.4%.

The Russell 2000 is up 17.37 points, or 1.1%.

For the year:

The S&P 500 is up 497.67 points, or 19.9%.

The Dow is up 3,506.49 points, or 15%.

The Nasdaq is up 1,484.52 points, or 22.4%.

The Russell 2000 is up 204.30 points, or 15.1%.