I have DNF'd a number of marathons when I knew by mile 8-12 that I was having a bad day and would not be able to approach my time goal for the race, and rather than run for another 1-2 miserable hours, I quit. The race volunteers were often sort of incredulous that someone who appeared to still be running fine and had no obvious physical problems wanted to drop out, but I never thought that finishing a race just for the sake of finishing was all that noble when finishing would cost me a long recovery.
The only time I ever dropped out of a race shorter than a marathon was when I pulled a hamstring one mile into a 5-mile local turkey trot. I managed not to fall down, turned around and started limping slowly back toward the starting line. A passer-by in a car pulled over and asked me if I needed a ride, and I gratefully took the ride back to the start/finish area, got in my car gingerly and drove home. I could not have run another step and would have had a very slow and painful time finishing the race at a slow walk.