LAST SEPTEMBER Mary Martin spent 10 days in a San Francisco hospital, wired up to monitors and recovering from the collapsed lung, broken ribs and fractured pelvis suffered in a car crash that made headlines around the world. Finally, when she was able to use a "dadburn walker," as she called it, she determined to leave the hospital. Slowly and painfully, she made her way, with a nurse at her side, to the back entrance and a waiting car.

But then she heard a strange noise. She looked up, and there, hanging out of the hospital windows, were nurses and doctors and interns--crowing. Crowing! Er-er-er-errrrrrrrrh! "Goodbye, Peter!" shouted the nurses and doctors of San Francisco General Hospital's shock-trauma unit.

"I tell you, that just did me in," Martin said. "That made me cry."

Mary Virginia Martin, 69 but still Peter Pan to generations of Americans, sees that as a happy ending to a painful episode. She is fond of happy endings, as befits the original cockeyed optimist, and if there's a positive lesson to be learned from an experience, she will learn it.

"I could have been on the other side of the car," she said. If she had been, she would have died, as her manager, Ben Washer, did. She could have been more seriously injured, like her friend Janet Gaynor, who was in the middle and is facing her fifth operation as a result of the crash. "So I feel I have some reason to be here. To finish something."

Martin was in town to tape a tribute to musical theater for PBS that airs at 8 tonight on Channel 26. The plan was to film the show, "In Performance at the White House," on the South Lawn--if it didn't rain. "Oh honey, as I'm saying this, it has started to rain!" she said, looking out the hotel window. "Rain yourself out!" she lectured the heavens. "We do not want you to rain on our parade!" (As it turned out, they finished all but two numbers and the finale before Monday's downpour. The show will be finished today.)

Martin retired from musicals after "I Do! I Do!" in 1969, exhausted and ill, facing an emotional collapse triggered by a hysterectomy and years of feeling "caged" by the circumscribed life of the theater. " . . . all I do is perform, sleep, rehearse, get ready for the next show, then perform again," she wrote in her 1976 autobiography, "My Heart Belongs." "At that point I don't think I had been inside a store for ten years . . . never in my adult life had I been able to catch cold, like other people, and go to bed. I couldn't have a headache, or get tired, or feel out of sorts. I had to go out there and perforrrrrrrm."

So she and her husband, Richard Halliday, retired to a farm in Brazil. But Halliday died in 1973, and she was devastated.

"I had never even walked across the street by myself," she said. "The biggest step I made was to walk across the street. I went to Bloomingdale's."

And did she buy anything?

"I bought something on every floor!" She giggled. "And haven't stopped . . ."

But two years ago she became the cohost of "Over Easy," a PBS daily talk show aimed at the over-40 market (Channel 26, 7 p.m.; Channel 32, 6:30). She knew little about TV talk shows, but she was game; she loved San Francisco, where the show is filmed; she'd only have to work from June to September, and she was ready to try again.

Although she said she was "an absolute spastic case" when she began, this year she has been nominated for an Emmy, up against Phil Donahue and Gary Collins, for best daytime talk show host. She finds this pretty funny.

"The first show I was supposed to start off. There is the audience, and all these television cameras on, and I wait and wait for a sign. The lights on all the cameras are red. Finally, I turned to Jim Hartz and said, 'When do we start?' He said, 'You're supposed to start. Go ahead.' I was waiting for the green light. I didn't know they only had red lights. When you drive, for gosh sakes, you don't drive on a red light."

The technicians stayed on after the show that day and wired green lights to the cameras to tease her.

On the show, she and Hartz talk with and interview people about medicine, interpersonal relationships, death, divorce and other subjects. "Many of the issues we deal with are women's issues," said producer Jules Power, who persuaded Martin to join the show. "And much of our audience is women."

"I didn't know that," said Martin. "I just knew I was having a lovely time.

"I feel better when I have a project. Everyone has to have goals. Because otherwise you sit back and you find yourself sitting like this she slumped dramatically into the chair . If I find myself doing that I just sit up straight, because that makes people get old quicker. I'm 69, but I feel 19 . . .

"When we talk about these issues on the show, my response is that I've lived it. I have lost the one human being in the world I loved the most, and I lost a deeply loved friend this year her manager, Washer . I'm still going through real sadnesses about other people that I know and love. But as long as I can I hope to get it across to people who are ill, or who have lost faith or the desire to live, that if you really and truly want to, that it's up to you. You can't just sit there and say 'I want it.' You have to work for it. It's up to you to get over grief, it's up to you to make up your mind to walk across the street . . .

"I have one friend that I am very fond of and her nature is not to do things, to just sit back and let it happen. And I've given her attitude lectures, and she says, 'You're right, you're absolutely right,' and she just sits back and won't do anything. I keep saying, 'Go on trips! Go places! Go with women, even if you don't know anybody, go!' "

There is something irresistible about Mary Martin. Maybe it's that she's an unabashed ham, and always has been. What would be strained cheerfulness in other people is somehow natural in her. She makes the saccharine songs in "The Sound of Music" palatable, and even today, with the high notes in her voice gone, she retains the indomitably sunny quality that added an extra dimension to "South Pacific," "Annie, Get Your Gun" and, of course, "Peter Pan."

And she is indomitable. She tripped over a fence during a telecast of "Annie, Get Your Gun" and finished a production number with blood gushing from a wound in her leg; she ran three miles (according to a pedometer) during each performance of "The Sound of Music"; she was strapped to a "torture wheel" and spun around in "Jennie" and had to get painkilling shots in her spine for months after being dropped 30 feet from a flight in "Peter Pan." During the first flying rehearsal for the 1960 telecast of "Peter Pan," she smashed into a brick wall and broke her arm when the technician controlling the wires dropped the rope. (He said later he had been distracted because he believed she was really flying.)

A few years ago she had a cataract removed, and recently she started wearing a "sacroiliac belt." After six weeks she threw out the walker she was supposed to use for 10 weeks after the accident, when the nurse pointed out she was just carrying it around. "I couldn't get around fast enough," she explained.

But, she said, she is not a difficult patient. "I do everything they tell me," she said. "I will swallow the doctor if they tell me to. Because I don't want to be ill. I don't want to lose that much time in life."

For several years after her husband's death she turned down everything. She moved to Palm Springs, Calif., and concentrated on "being a mother and grandmother. In 1976 her book was published, and in 1977 she returned to the stage in a play called "Do You Turn Somersaults?" which was not a success. She went back to Palm Springs.

"I didn't want to get back into something that took all my life," she said. "In the theater you have no other life."

But this, after all, is the woman who was taught this H.A. Walter poem as a child in Weatherford, Tex., and says it is still her creed:

I would be true, for there are those that trust me

I would be pure, for there are those who care

I would be strong, for there is much to suffer

I would be brave, for there is much to dare.

I would be friend to all--the foe, the friendless

I would be giving and forget the gift

I would be humble, for I know my weakness

I would look up--and laugh--and love--and lift.

So, stuck like a dope with a thing called hope, she's decided to keep on working. Having broken the ice with "Over Easy," she accepted an offer from "Love Boat" after six years of refusing it, convinced after the producers, writers and directors came to Palm Springs after her accident and offered her anything she wanted. "They were so sweet to do that . . . Ihad a marvelous time."

She hopes that "Over Easy" will be on next season--only half the funding has been raised--and is thinking about a television series and a movie. She just turned down a Broadway show because it had too much to do with death. "It was just too much. I've had too many tragedies around me, and I'm still having them."

She visits the still-ailing Gaynor whenever she can. Martin has dropped her suit against the cab company that owned the taxi they were riding in at the time of the accident, and the suit against the driver of the van who ran into them has been settled. The driver of the van was charged with drunken driving.

She travels to her farm in Brazil once a year, and visits her two children and six grandchildren, and goes off to be made a Distinguished Citizen of Parker County, Texas, (where she was born) and other such honors, and performs at benefits. Next year she is doing benefits only for shock-trauma units in hospitals, because she firmly believes the one at San Francisco General saved her life.

Her daughter, Heller DeMeritt, is married to an oil executive in Houston, and her son, Larry Hagman, plays an oil executive on "Dallas." Hagman puts on a British accent when they play cards, she said, and "drives me nuts." But other than that they get along well, she said, having ridden out the problems between them during his childhood when she was training her attention on her career rather than on him.

She said that the infamous "J.R." can also sing and dance, and her fondest wish is that he will play Captain Hook, with her granddaughter Mary Devon DeMeritt, now 8, playing Peter.

"I think he would be the funniest Captain Hook in the world . . . If I have to get into my dying wishes, I want him to play Captain Hook. I will be watching, from where I don't know, but I'll be watching."