Candidate referents for the use date back to at least the 19th century. The following are possibilities of the term's origin.
Euphemism for the devil: H. L. Mencken suggested that the phrase derives from Samiel, the name of the Devil in Der Freischütz, an opera by Carl Maria von Weber that was performed in New York City in 1825. The phrase "Sa' m Hill" can also be seen in the variant "Samil".
Store owner in Arizona: Sam Hill was also a mercantile store owner who offered a vast and diverse inventory of goods. People began using the term "what in the Sam Hill is that?" to describe something they found odd or unusual, just like the inventory found in Sam Hill's store. The original Sam Hill Mercantile building still stands on Montezuma Street in Prescott, Arizona, and is listed on the register of Historic Places.
Politician in Connecticut: An article in the New England Magazine in December 1889 entitled "Two Centuries and a Half in Guilford, Connecticut" mentioned that, "Between 1727 and 1752 Mr. Sam. Hill represented Guilford in forty-three out of forty-nine sessions of the Legislature, and when he was gathered to his fathers, his son Nathaniel reigned in his stead" and a footnote queried whether this might be the source of the "popular Connecticut adjuration to 'Give 'em Sam Hill'?"
Surveyor in Michigan: A possible origin for the phrase "Sam Hill" is the surveyor Samuel W. Hill, associated with the Keweenaw Peninsula area. Hill allegedly used such foul language that his name became a euphemism for swear words. In the words of Charles Eschbach, "Back in the 1850s the Keweenaw's copper mining boom was underway. There were about a dozen men who pretty much ran the Keweenaw. They were mining company agents, the 'go between' for the investors from Boston and the actual mining production people. Their names were attached to every report sent back to eastern investors. Among these company agents was a man named Samuel W. Hill. Sam was a geologist, surveyor, and mining engineer and had considerable power in the Keweenaw." According to author Ellis W. Courter, Samuel Hill "was an adventurer, explorer, miner, and surveyor. He had worked with Christopher C. Douglas and Douglas Houghton on the early State survey. His judgment was respected. Although he was a rough character, he possessed a big heart and in the fall of 1847 had risked his life to help avert a threatened food shortage in the Copper Harbor district. Generally he was regarded as a hero throughout the entire Copper Country, however, he was contemptuous of all the praise that was heaped upon him. Hill also gained a reputation as being one of the most blasphemous and obscene swearers in the Keweenaw Peninsula. Although he had a colorful vocabulary and told many a good story of his early adventures, his ubiquitous use of lurid cuss words became legendary. Whenever friends or neighbors retold his colorful tales in more polite society, they had to tame his unmentionables by substituting the sinless sounding words 'Sam Hill'. In time the expression, 'What the Sam Hill' spread far beyond the Copper Country. Today it has become a part of the American language. Few who utter these words ever heard of Samuel Hill, or know that he was the unconscious originator of a sinless synonym for profanity."
Adjutant General in Kentucky: Another possibility involves the former adjutant general of KentuckySamuel Ewing Hill, who was sent by the governor of Kentucky to see what was going on in reference to the Hatfields & McCoysfamily feud in 1887. Between 1880 and 1891, the feud claimed more than a dozen members of the two families, becoming headline news around the country, and compelling the governors of both Kentucky and West Virginia to call up their state militias to restore order. The governor of West Virginia once even threatened to have his militia invade Kentucky. Kentucky governor Simon Bolivar Buckner in response sent his adjutant general Sam Hill to Pike County, Kentucky, to investigate the situation. Newspapers from around the country awaited word from Hill to find out "what in the Sam Hill was going on up there".
Non-contender: Millionaire in the Pacific Northwest: The millionaire Samuel Hill, a businessman and "good roads" advocate in the Pacific Northwest, became associated with the phrase in the 1920s. A reference appeared in Time magazine when Hill convinced Queen Marie of Romania to travel to rural Washington to dedicate Hill's Maryhill Museum of Art. The fact that "Father of Good Roads" Samuel Hill hadn't been born when the figure of speech first appeared in a publication rules out the possibility that he was the original Sam Hill in question.