Warning: This post describes disgusting bodily functions.
When I was starting veterinary school, I visualized myself as "the boy-wonder equine surgeon". I really thought that I'd be doing nothing but horse-work. Not only do horses not have anal sacs, at that time I wasn't aware that these particular disgusting anatomical structures even existed. Had I known how much of my life would be involved with anal sacs, I might well have made a different career choice.
Sometimes people call them "anal glands" instead of "anal sacs". I believe this may be to avoid the aural confusion between "anal sacs" and "anal sex". Believe me, that is not nearly as funny as you think it is when it really happens in the exam room.
Dogs and cats both have these things. The actual anal glands are very tiny and surround the anus. Their secretions accumulate in the anal sacs. At the end of each bowel movement, the animal gives things one last squeeze and this empties a few drops from the sac. They fall freely and land on top of the waste-pile. The pheromones (hormone-like chemicals) act as a scent territorial marker.
In skunks and ferrets, the anal sacs become more specialized as the main musk glands. The skunk has a special expelling mechanism. In dogs and cats, they don't generally squirt the stuff across the room. The exception would be the large and frightened German Shepherd (aka "anal glands with teeth"). Any dog or cat experiencing an extreme "butt-pucker" moment (like... looking at me) may squirt the secretion onto the floor. The volume is more impressive when the Shepherd lets go.
The more common problem is the dog who doesn't spontaneously expel his anal sacs. This is most common in dogs with generally poor muscle tone: very small dogs, very old dogs, and very fat dogs. When the sacs don't empty, the secretion accumulates. This stretches the sacs, which creates pressure, which creates discomfort. That's why these dogs scoot around on their butts. They are trying to empty the sacs and relieve that discomfort. This (NOT worms) is the most common cause of butt-scooting. In order to relieve the dog's discomfort, a groomer or veterinary technician (OR a veterinarian, like me) empties the sacs by squeezing. If the dog is very fat, this may require a rectal examination to complete. Sometimes the secretion gets thicker and harder over time, making it harder to empty. Alas, this is a very common problem.
Dogs who have continual or recurring problems can have the sacs surgically removed. They are not a necessary structure, as their only purpose is to provide a scent territorial marker. Our pets have their territories marked by the fences and sidewalks. They can get along without these sacs.
One thing I failed to mention: this stuff stinks powerfully, much worse than mere feces. A few drops are supposed to last weeks outside. When the dog succeeds in squeezing a little out by scooting, it gets smeared on his hiney and you can smell him a mile away. When it all gets emptied in one spot, it is mighty stinky. Just washing doesn't fix it up. You've got to add some odor neutralizer, something a little like this: