One thing that you can do is to make sure that you use the bathroom before you engage in anal sex. You might find that it helps. It's also important to note that you might not really have to go to the bathroom during anal sex. What you may be noticing is the sensation of your partner moving in and out of your body. You will also feel full from penetration.
You can work on this issue by engaging in some anal training or anal play on your own. Start by using a dildo, plug, or dong that you will find comfortable. You don't want to start out by using something that is too large. You should definitely start out with something small. Use plenty of lube and play with it on your own. You'll eventually get comfortable with the sensations that you experience during penetration and during the motions of play. Think about how that feels similar, but also different, from actually needing to use the bathroom.
All that said, if you really do feel that you need to go to the bathroom then you should definitely stop and go to the bathroom.