Stocks shrugged off a sluggish start and ended mostly higher on Wall Street Friday.

The S&P 500 managed a modest gain, but still posted its first weekly loss in four weeks. The Dow Jones Industrial Average closed with a small loss.

Gains in communication services, health care and other sectors outweighed a decline in technology and energy companies. Treasury yields remained near their highest levels since June.

On Friday:

The S&P 500 rose 11.90 points, or 0.3%, to 3,465.39.

The Dow Jones Industrial Average dropped 28.09 points, or 0.1%, to 28,335.57.

The Nasdaq composite gained 42.28 points, or 0.4%, to 11,548.28.

The Russell 2000 small-cap index added 10.25 points, or 0.6%, to 1,640.50.

For the week:

The S&P 500 fell 18.42 points, or 0.5%.

The Dow lost 270.74 points, or 0.9%.

The Nasdaq dropped 123.27 points, or 1.1%.

The Russell 2000 gained 6.69 points, or 0.4%.

For the year:

The S&P 500 is up 234.61 points, or 7.3%.

The Dow is down 202.87 points, or 0.7%.

The Nasdaq is up 2,575.68 points, or 28.7%.

The Russell 2000 is down 27.97 points, or 1.7%.