U.S. policymakers grappled with unexpected complications yesterday as the fourth week of Iranian stalemate ended and a news period of uncertainty loomed.

The movement of the deposed shah, Mohammad Reza Pahlavi, from a private hospital in New York to a military hospital near San Antonio, Tex., undertaken after top-level policy deliberations here, entailed a major political shift as well as a physical one: For the first time the U.S. government has assumed open responsibility for the shah's person and it has begun to assume increasingly open responsibility for his future.

State Department officials acknowledged for the first time that the government is actively engaged in the search for a new haven for the deposed monarch. A source close to Pahlavi said his first choice is South Africa, where his fathr took refuge after British and Soviet armies invaded Iran in 1941 and where the elder Pahlavi died in 1944.

On another front, the attack yesterday on the U.S. embassy in Tripoli, Libya, presented already overburdened policymakers with a dangerous new outcropping of the Iranian conflict. Libya, for all its revolutionary fervor and anti-American rhetoric, has close economic ties with the United States and is the third largest supplier of imported oil to this country, behind Saudi Arabia and Nigeria.

The initial belief among senior officials is that this peculiar relationship of both acrimony and accommodation is likely to survive the new strain arising from the attack, if only because the economic stakes for both nations are so high.

Nevertheless, Libya's tolerance or perhaps even sponsorship of thee march on the American embassy -- in the face of U.S. sensitivity about the security of its diplomatic missions and U.S. appeals for increased embassy protection -- was a worrisome sign.

Washington responded by making clear that it is in no mood to be trifled with, issuing stongly worded State Department protests about the attack and a declalration by spokesman Hodding Carter that, as in the case of Iran, "We are not prepared to allow oil to be used as a weapon when it comes to our basic interests as a nation, or to impair our ability to function in ways that we feel are necessary to protect our lives or our honor."

A shutoff or even vigorous turns at the tap of Libyan oil flowing to this country would be a development of large proportions in the present context. In recent months Libya has supplied well over 10 percent of total U.S. imports, which translates into about 5 percent of total U.S. comsumption. Libyan crude is more suitable than other foreign supplies for making gasoline, and thus prized by U.S. refiners.

While Libya's maverick leader, Col. Muammar Qaddafi, has several times treatened on oil cutoff, his country has become highly dependent on the flow of about $6 billion a year in U.S. money and on a web of commercial and industrial relationships with American firms as well as American technology. About 40 percent of Libya's oil exports is sold to the United States.

Washington's top policy priority, despite the Libyan headache, continues to be the 50 Americans being held hostage in the Tehran embassy. The major diplomatic effort at the moment is in the forum of the United Nations Security Council in New York, where the United States is hoping for a strong and explicit demand that Iran comply with international law and practice by releasing the hostages.

It was clear from the outset of the crisis Nov. 4 that the future of the deposed shah as a key element, if not the key element, in its eventual resolution. The United States insisted from the first, and repeated in a remark by Hodding Carter yesterday, that "we will never turn the shah over to Iran."

At the same time, it was apparent that the United States expected that the shah's hospitalization would be for only a few weeks, after which he would return to his temporary home in Mexico. Movement of the shah outside U.S. juurisdiction would sap the force of the Iranian demand for his return, but it might also cause at least a spasm of anger on the part of the militants holding the Tehran embassy.

For this reason as well as the strong emotions about the former monarch in this country, the administration consistently described him as a private patient as a private hospital making his own decisions, without direction from or even direct contact with official Washington.

Starting Wednesday, the U.S. government had taken an unpulbicized part, at the shah's request, in making logistical arrangements for his making logistical arrangements for his expected move to Mexico after the emotionally charged Moslem holy days last Thursday and Friday. This plan and the government's official "hands off" posture were derailed by the surprise Mexican decision late Thursday that the shah would not be welcome to return there.

Since early in the week, doctors and officials of New York Hospital-Cornell Medical Center had been preparing themselves for the welcome departure of the shah, his entourage and the security and press problems they brought. Hospital officials passed word to the government, after Mexico refused Pahlavi's reentry, that "this hospital is not a hotel" and that, with the end of the current phase of his treatments, the shah should go elsewhere.

At top-level meetings in Washington on Saturday morning, the San Antonio facility was selected as the best interim "parking place" for the shah until a new overseas haven can be found.

In addition to the White House and State Department, top officials of the Defense Department, the Air Force and the FBI were involved in the decision and arrangements, which were ordered by early Saturday afternoon. The final decision was made by President Carter, according to officials.

Hospital facilities in New York and Washington, including the government's Bethesda Naval Hospital and Walter Reed Army Hospital, were ruled out to avoid raising a new specter of conspiracy in the minds of the Iranian militants holding the U.S. embassy.

Although official hopes to avoid government responsibility for the shah's future moves have been dashed, an advantage of the present arrangement is that the United States has a greater degree of control over their nature and timing.

This could be particularly important when the returns are in from the Iranian constitutional referendum, and the U.N. Security Council session is over. Both are expected by midweek, when a more fluid phase of the Iranian crisis is expected to set in.