Assuming by gas you mean natural gas. It can, and luckily is done more and more. It all comes down to money. If you are producing oil in a remote location, like a dessert or offshore, it can be expensive to transport or store gas which is produced as a byproduct. Transporting oil is easier and cheaper to do. You can just keep it in a tank and Transport it via a ship or truck. Gas needs a pipeline or converted to LNG (making it so cold it becomes a liquid). Both are expensive to do and if the price of gas is low, you won’t make any money of it or even lose money.
So it is just burned off.
However most countries now have environmental rules not allowing this practice anymore. Also the price of gas and market for gas has increased over the years making transporting the gas to where it can be used economically a better option
Latest Answers