The Senate relented a little yesterday and voted not to demolish the politically popular program of revenue sharing with states, as it struggled slowly toward approval of a balanced budget for 1981.

Before ending its 17-hour session early today and postponing final action until Monday, it approved an escape hatch through which the House and Senate could, by majority vote, evade their proposed curbs on spending in excess of intial budget targets.

Some senators contended that the two houses already have such power, but such influential committee chairman as Russell B. Long (D-La.), head of the Finance Committee, wanted explicit authority.

Over Republican objections that the Democratic majority was playing politics with budget deadlines, the Senate also agreed to advance from Sept. 15 to Aug. 28 the deadline for its final budget resolution this year, ostensibly to provide more time for fall campaigning.

Outnumbered but claiming the last word, Senate Minority Leader Howard H. Baker Jr. (R-Tenn.), an unsuccessful candidate for the GOP presidential nomination, suggested the change was being made to accommodate vulnerable Democratic incumbents and, smiling, wished them "the same level of success I had."

In the first change that either house has made in spending targets recommended by the two Budget committees, the Senate voted 59 to 30 to go along with a proposal by two freshmen senators, Nancy Landon Kassebaum (R-Kan.) and Bill Bradley (D-N.J.), to provide $700 million in general aid to states next year.

The House voted to eliminate the entire state revenue sharing program, thereby saving $1.7 billion, as part of a $611.8 billion spending resolution it approved Wednesday. The Senate Budget Committee also proposed elimination of the program, and the Senate voted Wednesday against shifting $500 million from water projects to revenue sharing.

In restoring $700 million of the $1.7 billion total that the states had expected, the Kassebaum-Bradley amendment would keep the program alive, although at about 40 percent of its current level.

It would not upset the budget balance, because categorical grants to state and local governments would be cut by an identical amount, with details to be worked out later by congressional committees.

Victory of the Kassebaum -- Bradley proposal followed defeat of a more ambitious plan by Baker to restore the $1.7 billion in state aid. Baker's proposal lost 49 to 44.

Baker had been an original sponsor of the program, under which states received on a no-strings-attached basis about $54 billion in federal revenues over the past eight years.

Baker called the program a lifeline to state and local governments and a deterrence to federal extravagance. The Budget committees had viewed it as a luxury that the federal government could not afford when Congress was slashing national programs in order to fight inflation by ending federal budget deficits.

The Survival of state revenue sharing is not guaranteed, however. The kassebaum-Bradley proposal must still survive a House-Senate conference to resolve differences in the budget restrictions. The conference is expected to begin soon after the Senate acts, in hopes of finishing by the May 15 deadline.

As the Senate moved at a snail's pace through a big stack of amendments, it defeated, 39 to 53, a proposal to cut its $612.9 billion budget draft by $7.3 billion to provide a tax cut to stimulate investment.