How would you get a magnetar close to Mars, within the solar system?
OK, let's leave that to one side, but the Earth's magnetic field is of order $10^{-4}$ Tesla at strongest. As the dipole field of a magnetar diminishes as $r^{-3}$ and could be as high as $10^{11}$ Teslas at the surface of the magnetar, at a radius of 10 km, then the magnetar woud need to be at a distance of $10^{6}$ km to surround Mars with a field of $10^{-4}$ Tesla.
The problem is that the radiation coming from the magnetar in the form of charged particles accelerated from the magnetic poles would completely dwarf the charged particle radiation from the Sun at Mars.
So no, a nearby Magnetar would not save Mars' atmosphere - quite the reverse.
EDIT: A BOTE calculations: If we look at the Crab pulsar - not quite a magnetar, but close - it is calculated that 10% of the rotational KE being lost ends up in synchrotron raiation from charged particles. That's about $10^{30}$ Watts. So there is at least $\sim 10^4$ solar luminosities, just in the kinetic energy of relativistic particles.
Magnetars are also very strong and variable sources of hard X-ray and Gamma ray radiation. Typical magnetar bursts/flares can release $10^{7}-10^{9}$ solar luminosities of hard X-rays and Gamma rays over periods of 1-40 s. That should fry any atmosphere (or anything else) that was only $10^{6}$ km away!