Lifting the leg helps them "mark their territory" by being able to pee higher up on tree stumps, fire hydrants or whatever. It's something they would have used in the wild in order to tell where the boundaries of the pack's territory was. Incidentally, many dogs that are neutered as puppies don't learn to lift their leg because their hormones don't kick in to make them territorial.