Ronald W. Pelton, accused of selling secrets to the Soviet Union, was denied bail for a second time yesterday by a federal judge who cited a report that Pelton had taken an opiate three or four days before his arrest last month.

According to a pretrial report cited by U.S. District Judge Frank Kaufman in Baltimore, Pelton, 44, a former National Security Agency analyst, acknowledged to a court interviewer that he intermittently made use of the narcotic drug Dilaudid, a habit-forming painkiller that sometimes is used as a heroin substitute.

Judge Kaufman said Pelton's drug use, as well as the spy charges against him, were sufficient reason to deny bail. The danger that Pelton might flee "seems to be so clearly presented that there is little need to review in detail" the facts surrounding his case, he said.

Pelton's attorney, Fred Warren Bennett, said later that the government had failed to provide "a shred of evidence" that his client would either attempt to flee or pose a danger to the community if released.

The government has charged Pelton with selling a classified report on the Soviet Union and other secrets to Moscow during a five-year period after he left the security agency in 1979.

The judge said that according to the pretrial report, Pelton "acknowledged the illicit use of an opiate-based drug for two or three months on an intermittent basis and last used the drug on an intravenous basis three or four days before his arrest."

Bennett said his client's use of Dilaudid was "recreational" and that Pelton was not addicted.