The Senate last night neared completion of an overhaul of the nation's federal criminal laws, a project of enormous proportions that would, among other things, severely restrict the broad discretionary powers of judges in passing sentence on criminals.

If enacted, the legislation will represent the first consolidation of laws that Congress has scattered through the statute books in 200 years of legislative activity.

Sen. Majority Leader Robert C. Byrd (D-W.Va.), who had planned to keep the Senate in session late last night until the bill was completed, said the debate on amendments would require at least another day, and he set a deadline for a vote on the measure for 6 p.m. Monday.

The Senate is scheduled to resume the debate on the bill - the product of 10 years of bitter dispute between Senate liberals and conservatives - at 10 a.m. today.

The new code would create a Federal Sentencing Commission that would write sentencing guidelines as nearly fixed as possible, for various crimes. Federal judges would be expected to follow the guidelines and the maximum term could not exceed the minimum by more than 25 percent.

For six days, liberals and conservatives in the Senate have been debating scores of amendments to the bill.

Senate conservatives yesterday won one strategic battle involving federal obscenity statutes, but lost on two others.

An amendment by Sen. Charles Mathias Jr. (R-Md.) that would have restrained federal prosecutors from "shopping" for a jurisdiction in which to prosecute obscenity cases wasshelved by a 61-26 vote.

Mathias, warning against the "nibbling away" of constitutional free press guarantees, cited a recent case in which the publisher of Screw magazine was prosecuted in Kansas after postal authorities there bought subscriptions.

Mathias' amendment would permit a defendant to request his case to be tried where he maintained his primary place of business.

Among those who opposed the amendment was Sen. Orrin G. Hatch (R-Utah), who said New York City pornographers would be able to send obscene literature to South Carolina but be tried in New York City, where obscenity standards are more flexible.

However, the conservatives, led by Sen. James B. Allen (D-Ala.), lost by a 49-38 vote in an attempt to remove from the bill a clause that would permit prosecution on charges of conspiracy to disseminate obscene material only in the district where the conspiracy occurred.

Similarly, liberals were able to keep in the bill - for the time being, at least - an amendment by Sen. James Abourezk (D-S.D.) that would block obscenity prosecution in states where the obscene material in question is legal. A fight over that provision is expected today.

The Senate also adopted yesterday an amendment by Sen. Gary Hart (D-Colo.), which prohibits witnesses testifying before congressional committees from offering national security as an excuse for not telling the truth.

"In the past, administration witnesses have sometimes felt torn between an obligation to tell the truth to Congress and instructions they may have received not to reveal the details of a program," Hart said.

He did not mention by name former CIA Director Richard Helms, who late last year pleaded no contest to a misdemeanor charge in connection with statements he made before the Senate Foreign Relations Committee about CIA involvement in Chile. In fact, Hart said, "This amendment is not an effort to make anyone who has been in this dilemma in the past look bad."

Sen. Edward M. Kennedy (D-Mass.), floor manager of the bill, pointed out there is now nothing in federal law that permits the use of national security as a defense for untruthful statements, but he said the amendment was useful to "nuderscoe" the need for trutful testimony.