Rep. John Anderson (R-Ill.) wound up the Middle East leg of his foreign campaign tour today by getting on the list of American politicians whom President Anwar Sadat calls "my friend."

Bestowal of the title has become a ritual in Middle East diplomacy, beginning with Henry Kissinger and moving through President Carter and special negotiator Sol Linowitz. For Anderson, however, it had special significance. Sadat and members of his government were troubled by the independent candidate's statements in Israel and Sadat said publicly that he had expected to "have a row" when the two men met today at the seaside resort of Alexandria.

Instead, Sadat told reporters, the 90-minute meeting at his summer residence was "a very happy occasion" during which Anderson explained to the Egyptian leader's satisfaction his stand that Jerusalem should be the capital of Israel as the final state of peace negotiations.

"I asked his opinion," Sadat said. "He said quite firmly and candidly that this will be the last phase of the peace process after autonomy is achieved and we reach the last phase of negotiations. I was quite satisfied." a

Sadat's understanding attitude ended what Anderson's campaign advisers saw as the major risk of his decision to take his quest for the U.S. presidency to the Middle East and Europe. The trip provides a novel backdrop for television coverage and gives the independent candidate an aura of foreign policy experience, but at the same time exposes him to the risk of an embarrassing snub.

Although King Hussein of Jordan found that he was "too busy" to receive the candidate, Anderson's talks with Prime Minister Menachem Begin of Israel and his warm reception by Sadat allow him to claim successful contacts with leaders in both Israel and Arab countries.

To make the most of these contacts, Anderson stressed different facets of his positions on the Middle East according to his audience.

In Jerusalem, he emphasized his long record of support for Israel and his belief that Jerusalem should end up as the permanent capital of Israel at the end of peace negotiations.

In Egypt, he repeated the same position, but stressed his belief that such a result could only grow from negotiations in which all parties would participate.

Anderson also said in Jerusalem that he knew of no other country in the Middle East besides Israel with which the United States has such a special strategic relationship.Here in Cairo, he told reporters that Sadat reviewed with him Egypt's granting of military facilities "to make it possible for the United States to play its role in the Middle East and world affairs."

Anderson's chief audience in both Israel and Egypt, however, was in the United States. His advisers said privately that one of the trip's main purposes was to increase his visibility with American voters during the Republican convention and, in the words of one of his media strategists, "to show he can hold his own with the heavy hitters on the international scene."

Anderson, speaking with several American reporters in his hotel suite overlooking the Nile, defended his decision to campaign for the U.S. presidency abroad by citing the need to gain "some basis of rapport with the leaders of Europe and the Middle East."

"For me, it was the most logical thing in the world," he said, slipping easily into a hustings-style barb at President Carter and Republican candidate Ronald Reagan. "It is not the easiest thing in the world to frame your perspectives on world issues sitting in Washington or in Pacific Palisades . . ..It's different when you sit with them in a one-on-one stature. Maybe Mr. Reagan can get it from the ranch out there."

When asked later at a news conference what he has learned during his visits to Israel and Egypt, Anderson said he would first have to return to Washington for a "process of distillation."

"I certainly have not had time obviously in the three or four short days I have been in the Middle East to distill all the impressions, all the thoughts, that I have gathered," Anderson added. He is to visit West Germany on Sunday.

Anderson said he had already met all the heads of government with whom he is meeting on this trip. His four-day trip to Israel last week was his fourth to the Jewish state and he has been to Egypt at least lonce before. Anderson said, however, that the opportunity to discuss world issues with foreign leaders provides new perspectives and prepares him to deal with his foreign colleagues if he succeeds in becoming president.