Soviet President Mikhail S. Gorbachev was quoted Saturday as saying pro-independence republics ultimately may leave the Soviet Union, but he said they would be better off staying in a reshaped federation.

The German news weekly Der Spiegel reported that the Soviet leader, in an interview earlier in the week, congratulated those who voted in the March 17 referendum to preserve the union in the face of separatist demands."In this difficult time of transition, laden with great worries, the people did not lose their heads but rather declared faith in our values and principles," Gorbachev was quoted as saying.

It was his first comment on the mixed result of the referendum, in which six of the 15 Soviet republics did not take part. In the other nine, substantial majorities were reported in favor of preserving the union.

Spiegel quoted Gorbachev as saying it would be "impossible, madness" for republics to secede for historical and demographic reasons, but if they went through the process laid down in the constitution, they could do so.

"Ultimately, international-style relations would be established," he said.

Pressed on the point, he said Moscow should take the same attitude it took when its former satellites in Eastern Europe wanted to break their bonds with the Communist giant.

"We thought about it and came to the conclusion: Let these countries decide themselves what they need and what kind of a society they want to have," he was quoted as saying.

But Spiegel reported that he felt that adhering to the new form of union, soon to be decided, offered the best way for the republics to attain freedom and autonomy.

Gorbachev described his country as a community of peoples melded together over centuries, saying that 70 million had settled outside their home republics. Thirty million mixed marriages had resulted, and some borders between republics were not set in law, he said.

"If all that is divided by separatists and is undone, what a sorrow it would be," he was quoted as saying.