We think of humans as having obsessive compulsive disorders, but animals can be afflicted by them, too.
If your dog is obsessed with certain activities, such as licking their leg, he/she may have what animal behaviorists call canine compulsive disorder. It's a behavioral disorder related to anxiety, and scientists estimate that it affects two percent of the dog population.
Any range of odd, unexplainable repetitive behaviors may indicate the presence of the disease. This includes excessive licking, but also tail chasing, chewing with an empty mouth, and barking repetitively without any change in volume or intonation. It's a serious problem that may not only interfere with the human-animal bond, but that can lead to physical problems for the dog. For example, dogs who lick themselves raw are prone to infection, and some dogs with this disorder will quit eating or drinking.
Because the problem is tied to anxiety and stress, one thing you don't want to do is punish your dog, which will only increase his stress and worsen the problem. Also, the longer the problem goes ignored, the more difficult it is to treat. See a veterinarian who works with animals with behavioral problems. Behavior modifications such as stabilizing the environment, interacting consistently, redirecting the animal's behavior, and increased exercise benefit some dogs.
Also, at present, research is being conducted to find out whether dogs with this disease will respond to a drug called a selective serotonin re-uptake inhibitor, which has been successful in treating obsessive-compulsive behavior in humans.