Here is a reference you might want to read:
A Guide to Dog Anal Gland Problems
It includes :
"Tips To Keep Prevent Anal Gland Problems:
•Keep your dog at a healthy weight. Obesity increases the likelihood of anal sac problems.
•Feed a high quality food that contains a named meat as its first ingredient. Add carrots, bananas, pears, squash, peas, bran and olive oil to your dog's rations. These foods will provide bulk and improve
•your dog's overall digestive health.
•Regular, vigorous exercise will stimulate the gastrointestinal tract.
•Dog digestive problems such as diarrhea and constipation are often improved by the addition of a probiotic supplement. These supplements will increase the beneficial bacteria naturally present in your dog's gut."
You often see this problem after a dog has had a lot of loose stools. They don't have to bear down to defacate, so they aren't emptying the anal gland each time. So, treating for loose stools can sometimes clear the problem. Changing food may be a good idea. Yorkie stools should be tiny little tootsie roll type stools. Keep treats healthy and to a minimum and feed a premium food. I find mine do well with Solid Gold Just a Week Bit. Others like Orijen, Merrick, Tast of the Wild, really any of the premium foods should do ok.