In the old days, sales representatives from drug companies would chat up local pharmacists to learn what drugs doctors were prescribing. Now such shoulder-rubbing is becoming a quaint memory — thanks to vast databases of patient and doctor information being used by pharmaceutical companies to market drugs.

The information allows drug makers to know which drugs a doctor is prescribing and how that compares to a colleague across town. They know whether patients are filling their prescriptions — and refilling them on time. They know details of patients’ medical conditions and lab tests, and sometimes even their age, income and ethnic backgrounds.

The result, said one marketing consultant, is what would happen if Arthur Miller’s Willy Loman met up with the data whizzes of Michael Lewis’s “Moneyball.” “There’s a group of geeks, if you will, who are running the numbers and helping the sales guys be much more efficient,” said Chris Wright, managing director of ZS Associates, which conducts such analyses for pharmaceutical companies.

Drug makers say they are putting the information to good use, by helping a doctor improve the chances that their patients take their medications as prescribed, or making sure they are prescribing the right drug to the right patients.