Looking at the phrasing carefully, "all but 9 die" means that all the sheep except 9 died.

So if the farmer started with 17 sheep and all except 9 died, then 9 sheep are left alive.

The answer is 9 sheep.
