THE PRESIDENT'S Sunday-night speech on AIDS was sensible. Much talk had preceded the event -- Mr. Reagan's first speech devoted entirely to this subject -- and it was rumored that warring camps within the administration were trying to persuade him to take different positions. In the end the speech took something from both sides and set out a cautious approach.

Compassion was the keynote, as it was in Vice President Bush's speech on the same subject the following day. Both emphasized the human tragedy of the disease and insisted that its victims be treated without discrimination. "We must wage an all-out war against the disease," said the vice president, "not against people." Education was stressed, as was a commitment to treatment and research. All this will cost billions in the next few years; the administration is now on record as being willing to pay the price.

On the question of testing, the president stressed the moral obligation of government to protect those who do not have the disease. He called for mandatory AIDS tests in two areas. Would-be immigrants have always been subjected to tests for communicable disease, and the government is well within its rights in excluding carriers of this deadly virus. Federal prisoners will be tested too. Here, there is a special obligation to identify carriers since society must protect those uninfected prisoners who must live in close proximity with carriers in a situation where rape is always a threat.

In other areas, the president's decisions are tentative. He calls for review of conditions in veterans hospitals to determine whether tests should be given routinely to protect health-care workers and other patients. He encourages the states to offer AIDS tests to those who apply for marriage licenses and those who use clinics that treat venereal diseases and drug problems. He asks the states to take steps to protect their own prison populations.

In a world unlike the one we know we live in, rigorous self-discipline and intelligently understood self-interest might be enough to stem the spread of AIDS. But they are not. That's why it is so important to take special measures to limit the spread of the disease. Safe sex should be taught; prisoners infected with the AIDS virus should be housed separately from others; hospital workers should be on notice about AIDS-infected blood. In light of the risk that is involved, these precautionary steps are neither unduly harsh nor unreasonable.