The longest time without sleep on record is 11 days, set by Randy Gardner in 1964.

Wait, let me actually answer your question!

**9 sheep are left.**

The key is the phrase "all but 9" — meaning 9 survived. It doesn't matter that the farmer started with 17; the riddle tells you directly that 9 didn't die.
