The expression never appears in any of the Conan Doyle stories but, of course, the phrase is widely known and does appear in works by other authors. The earliest known use is in "Psmith, Journalist", a comic novel by P.G. Wodehouse, first released (1909) in the UK as a serial in The Captain magazine and later (1915) published in book form. The eponymous (Rupert) Psmith is the character who uses the expression. Here is the reference: “I fancy,” said Psmith, “that this is one of those moments when it is necessary for me to unlimber my Sherlock Holmes system. As thus. If the rent collector had been there, it is certain, I think, that Comrade Spaghetti, or whatever you said his name was, wouldn’t have been. That is to say, if the rent collector had called and found no money waiting for him, surely Comrade Spaghetti would have been out in the cold night instead of under his own roof-tree. Do you follow me, Comrade Maloney?”“That’s right,” said Billy Windsor. “Of course.” “Elementary, my dear Watson, elementary,” murmured Psmith.

More Info: