Stocks were stuck in a narrow range on Tuesday as positive corporate results were tempered by concern that consumer demand remains weak.

Analysts said the day's news, including a surge in profit from Goldman Sachs , was already accounted for after optimism that banks' earnings will be stronger than anticipated lifted the major U.S. stock indexes more than 2 percent on Monday.

Investors were also cautious, with other major companies set to reveal their scorecards later this week, including Bank of America and General Electric . Intel is expected after the closing bell.

Data showed June retail sales rose more than forecast, but a big part of that gain was due to rising gasoline prices. Excluding autos and gas sales, retail sales registered a fourth consecutive monthly decline.

A rebound in sales is considered vital for the U.S. economy to bounce back from recession, as consumer spending accounts for roughly two-thirds of the country's economic activity.

The consumer remains extremely weak and that's the biggest headwind we face, in terms of the economy picking up steam, said Michael Sheldon, chief market strategist at RDM Financial in Westport, Connecticut.

As a result, investors face a large amount of uncertainty over the near term as to the next direction for the market.

The Dow Jones industrial average <.DJI> rose 3.32 points, or 0.04 percent, to 8,335.00. The Standard & Poor's 500 Index <.SPX> added 1.64 points, or 0.18 percent, to 902.69. The Nasdaq Composite Index <.IXIC> gained 3.88 points, or 0.22 percent, to 1,797.09.

Goldman Sachs Group's surge in quarterly profit handily beat expectations, but its stock was off 0.8 percent at $148.30, retreating from a 5 percent jump in the previous session.

Johnson & Johnson's profit also surpassed forecasts and the Dow component rose 0.5 percent to $58.02. This earnings season is under particular scrutiny as investors look for signs of economic improvement.

Indeed, comments from the chief executive of railroad company CSX Corp that the worst of the recession seems to be over helped bolster stocks.

The company, which reported better-than-expected results on Monday after the closing bell, saw its shares climb 6.7 percent to $34.72. The Dow Jones Transportation Average <.DJT> gained 1.2 percent.

But Dell Corp limited gains after the personal computer maker forecast lower gross margins in the quarter as demand has shifted toward cheaper computers such as netbooks. Dell's shares slumped 7.7 percent to $12.02.

(Editing by Jan Paschal)