John B. Anderson yesterday said he would consider dropping his independent candidacy for president if he became convinced that continuing it would put Ronald Reagan in the White House.

The Illinois congressman, his independent candidacy only one day old, said he would "do what was right" if it became apparent he had no hope of election and Reagan appeared on the verge of winning the presidency.

"I care enough about this system and this country that I would not blindly and stubbornly and out of pure vanity and ambition stand in the way if the country had to choose between the lesser of two evils, making sure they got the lesser of two evils," he said.

Anderson, who dropped out of the GOP presidential race Thursday, made his comments during a luncheon with editors and reporters at The Washington Post. He had been asked what he would do next October if it appeared he had little chance of winning and he was drawing more votes away from President Carter than Reagan.

At first he hesitated, noting that if he said, "I'll step aside," supporters would say, "Why should we go to work body and brain, brawn and dollars for this guy who doesn't know from one day to the next whether he's in or out?"

But a moment later he added, "I want to reassure people that I would always hope that I would make the kind of judgement that would be good for my country and that I could put aside my ambitions and my career and do what was right."

Earlier, he had made his distaste for Reagan and his conservative politics clear. The former California governor, he said, "isn't just trying to turn the clock back. He wants to take whole years off the calender."

He also had some harsh words for the Republican Party, of which he was a loyal member for 30 years. Republicans, he said, "have much more a bookkeeper mentality" than Democrats and don't let compassion" stand in the way of policy.

Anderson, a 10-term congressman who until recently held the party's third ranking leadership position in the House, came under harsh criticism earlier in the day from Republican National Chairman Bill Brock.

In an unusually strongly worded statement, Brock accused the congressman of becoming an independent only out of "vanity," misplaced "messianic vision" and "personal" ambition."

"I am deeply disappointed in today's John Anderson," he said. "He was content to seek the presidency under the established rules as he knew them, but now having lost under those rules he is unwilling to abide by them."

Anderson begins his first two-day campaign swing as an independent today with a trip to New York City, where he is scheduled to speak before a women's NAACP conference and a gathering for Solidarity Day of Soviet Jewry.