So for the longest time I could not pass gas without being on the toilet. Sometimes I would pass gas in my sleep but rarely and never consciously.
Now I can with these stipulations; I am laying on my left side or on my stomach. I can do it standing but it's much more difficult to if it's more than just gas.
The trick is very slowly trying to fart, you can practice in the toilet but it can be problematic because of position. When you are learning to do this again you may want to grab adult diapers or have something in case you pass something other than gas.
When on the toilet (or wherever you want to learn) try to slowly poop, if you think it's just gas or not. But getting this very slow is important, you need to learn to get good control of "expressing" your anus. Eventually I have trained my body to pass gas again.
This has been a very slow stressful process but I believe it is something anyone else who suffers from gas should try. Since learning to do this again I have improved my sleep and my general life. I am passing gas in my sleep more often without the "accidents" I experienced before.
Again I hope this helps someone. Gas was killing my sleep due to discomfort and being totally awake by the time I finished on the toilet. Now I am passing gas in my sleep for the most part (being able to sleep on my tummy and side). Sometimes if I wake up I just get into position and try to fart, your body and you will start to feel if it's just gas or if you need to get up and go.
Good luck.