Some dogs need their anal glands expressed. A vet will usually put on gloves, then put his finger in your dog's rectum and stimulate the anal glands. Next he will mop up the mess with some gauze or cotton balls. The problem is solved for about 6 months, in my experience.
Also, you can learn to do this yourself.