Sometimes it's a lack of B12. Sometimes it's an inability to absorb it. Sometimes it's something else - the doctor can work it out.
My grandmother died of pernicious anemia in about 1935. There was no treatment back in those days, other than eating raw liver which didn't work if you weren't able to metabolise B12 properly from your diet. I did hear about when they discovered that eating raw liver was saving lives, though - they saved everybody on their trial except one lady who said she'd rather die than eat raw liver. My grandmother did eat raw liver but it was not a good enough fix for her. It kept her going for about ten years, though.
When my grandmother's sister got pernicious anemia in 1970 (I think), she was easily treated with a monthly injection of B12. She did fine. She had a long, healthy, active life and was not inconvenienced by the monthly injections. My great aunt had been young enough to not get pernicious anemia until AFTER injections were available. My grandmother would have lived much longer too, if injections had been available for her. They didn't have B12 supplements back then, either.
My great aunt lived for over 25 years after her pernicious anemia diagnosis. And it was her heart that slowly gave out, when she was 101. Otherwise she would have kept going, getting her monthly B12 injections, still active and fit, for who knows how long? We always joked with her that it would take a silver bullet to get rid of her.
So even if it's the worst possible pernicious anemia, you'll be OK. And it could be even better - a vitamin pill may be all you need. And if it's just a short-term lack of B12 and not pernicious anemia - you won't have to take a supplement for long.
Marg