When I have gas in my stomach and can't get rid of it I find that laying on my right side helps with the gas pains and helps relieve the gas in my stomach.
The way it works is right side sleeping relaxes the lower esophageal sphincter, between the stomach and the esophagus.
I've also heard that you can sleep on your left side when you have gas so either way should work but the right side sleeping works best for me.
Sleeping on the left side helps to keep the junction between stomach and esophagus above the level of gastric acid.