In these long hot dog days of August, John B. Anderson is undergoing a public transformation as he moves from city to city.

"St. John the Righteous," as some of his colleagues in Congress have called him, is more and more emerging as "John the Politically Expedient."

He spends his time with corporate executives, politicians, special interest groups and television interviewers, not college students as did the Doonesbury candidate of old.

He speaks from carefullly crafted -- and emotionless -- prepared texts. He is whisked away from reporters to secret fund-raising efforts and meetings. And he lustfully eyes the Democratic National Convention in New York next week, hoping for a bloodbath that might produce a major Democratic running mate for him, and a corps of disillusioned Democratic supporters.

The single best example of the transformation of John Anderson is his on-again, off-again flirtation with Sen. Edward M. Kennedy.

Anderson, the longshot independent hopeful, and Kennedy the longshot Democratic hopeful, created a major flurry last week. Anderson emerged from a meeting strongly hinting he would drop his candidacy if Kennedy won the Democratic nomination.

A few days later the political odd couple made back-to-back appearances before the National Urban League and Anderson added to the tease, saying Kennedy's speech included "some very excellent remarks."

But then Anderson began carrying a transcript of his Kennedy remarks in his breast pocket. At each news conference, he would quote selectively from the transcript, maintaining that his intentions had been misinterpreted.

Inch by inch, as questions persisted, he retreated. Finally, on Thursday, Anderson said he was in the race to stay regardless of whether Kennedy won the nomination. "I'm not really sorry . . . The only thing I'm sorry for is my expression [words] weren't sufficiently artful."

There are several explanations for the brief Anderson-Kennedy courtship. Anderson's official one is that he was trying to build a bridge to Democrats and his remarks were blown out of proportion. He added a caveat in a private meeting with auto industry executives, telling them, "The campaign needed a little publicity."

His aides offer a more sympathetic account. They say Anderson felt he had given a lawyer-like initial statement on Kennedy, but finally grew frustrated with questions about his position and ended up changing his stand to put an end to the questions.

Regardless, the impression left was that Anderson had simply said the politically expedient thing each time.

This episode comes as Anderson's campaign enters a crucial new stage.

After three months of campaigning as an independent, he has crossed several major hurdles. He has put together a credible national organization. His supporters have collected more than a million signatures, enough to qualify him for a spot on the ballot in 32 states and the District of Columbia, although he has been formally certified in only 10 states.

And he now is being accorded all the trappings of a major presidential contender. Leaving Cleveland today, for example, his motorcade included 12 patrolmen on motorcycles, 10 staff and police cars, one ambulance and a press bus.

But, according to polls by the George Gallup organization, Anderson's support has begun to wane. In the latest Gallup Poll, Anderson's support had dropped to 14 percent from a high of 24 percent in mid-June. President Carter, beset by problems with his brother, dropped 35 to 31 percent in the same survey; GOP nominee Ronald Reagan went up from 33 to 45 percent.

This is reflected on the campaign trail. When an elderly woman in Denver heard this week that three hecklers had thrown eggs at Anderson, she said, "I didn't think he was that popular."

The problem is that many people still don't think Anderson has a chance to win. In a Los Angeles Times nationwide poll last month, only 8 percent of Anderson's supporters and 3 percent of all voters thought the Illinois congressman would become president.

His base of support is narrow. His supporters tend to be young, liberal, well-educated (half have been to college), affluent (45 percent have annual family incomes over $25,000) and eastern-based.

This is why August and the Democratic convention are so important to the Anderson campaign, which realizes that a large part of the candidate's appeal is an unhappiness with Reagan and President Carter, the likely Democratic nominee.

One three-paragraph fund-raising letter statd this with delightful simplicity. "Dear Friend," it said. "There are two reasons I need your financial help and need it now: Ronald Reagan. Jimmy Carter. Sincerely yours, John B. Anderson."

But now Anderson is trying to broaden his base, appealing to blacks and other groups. His most important decision of the month is the picking of a running mate.

If he can find a widely known national figure to join his ticket, his candidacy would gain credibility. For someone trying to run a national unity campaign, "it wold make a certain sense to have a Democratic-running mate," he told a news conference here today.

But the willingness of any widely known, Democratic figure to join his campaign may depend on how disillusioned they are with the Democratic nominee, and how they regard Anderson's chances of victory.

Several Democrats have been mentioned in this regard. Among them are: New York Gov. Hugh Carey, New York Sen. Daniel Patrick Moynihan, Rep. Morris Udall of Arizona, former Texas congresswoman Barbara Jordan, Boston Mayor Kevin White, former Massachusetts Gov. Michael Dukakis and Colorado Gov. Richard Lamm.

Anderson said he doesn't want to appear to be "a vulture hovering over a carcass," but "I'll be more than a disinterested observer" of what happens in New York.

Much, he said, would depend on how bitter the debate is over the party platform and on what attitude the Carter forces take. "Obviously, if everything ends in sweetness and light and everyone singing Auld Lang Syne" things will look one way, Anderson added, "wherein a certain friction would pose other possiblities."

Later, he added that even if the convention produces a "facade of unity" he thinks Democrats will still be attracted to him.