They cost more money per year to keep alive while they're dying, and they contribute less to the economy (because they die early). The indirect costs of their mortality are far greater than the direct savings.
Speaking from europe where healthcare is basically free.
Medical care for these patients is extremely expensive. Each surgery costs around 50 to 60 thousand euro and it's not uncommon to get 2 or 3 of those before dying. Add to that the frequent visits to the doctor's office, the oxygen tanks if needed, the medications, etc. The other option would be to just "let them die" but that's not what we decided to do as a society.
The trend is that we are now able to keep them alive slightly longer, ( at a higher cost) and that they start developing symptoms slightly later thus reducing the potential "benefit" for society.
But, per that same study, "society" would net — inclusive, among other things, of pension funds not disbursed — lose ~€70k per individual, while saving less than €5k on medical expenses.
This is true, and I once quoted sources like it as a smoker that thought sin taxes were too high, but the larger truth is that smoking should be discouraged because we should make it socially unacceptable to stop our children from getting hooked like we did. I quit. It's good that I did for its own sake. We're not just numbers on a policy planner's spreadsheet.