I've had this happen on two SNES games, Super Mario World and Legend of Zelda: Link to the Past. I wonder what are the criteria for such a thing where if you replace the battery, the saves are retained. I imagine it must be harder for RPGs like Fire Emblem and Final Fantasy, but I wonder how common this must be.
Of course, this is different for flash based saves for titles like Sonic 3 and GBA games.
It depends on the SRAM and perhaps if there are any caps that might help retain power. Capcom CPS2 boards have SRAM holding decryption key data that Razoola has tested after cutting the battery can retain the data in SRAM for about an hour.
Sonic 3 is FRAM based, not flash. If it's battery backed it'll eventually get erased or at least corrupted.
Some GBA games (like Kirby: Nightmare in Dreamland and some others) are battery backed though the majority are saved via eeprom. Other games (like SMA4) are saved in flash memory. Still others (like Kirby and the Amazing Mirror) are saved via Fujitsu FRAM.