Posted by Bruce Kahl on June 22, 2000
In Reply to: Derivation of "What in the Sam Hill......" posted by Dave McCrabb on June 22, 2000
Merriam-Webster has a discussion of this phrase and others at the link below.
Seems your phrase, as in "What in the Sam Hill are you doing?", is a euphemism, an inoffensive expression used to substitute for terms that might offend or suggest something unpleasant aka "Minced oath". The hill part is thought to be a stand-in for the word hell, but why Sam? Theories abound, but proof is scarce.