What determines how long a planet will keep its atmosphere is the strength of the planet's gravity versus the random thermal motion of the molecules in its atmosphere.
The atmosphere is a gas, and all gasses have molecules that move around with velocities that are dependent on the temperature. High-temperature gasses move faster, and low-temperature gasses move more slowly. Each molecule of gas will have a velocity $v_{\text{gas}, \text{average}}=\sqrt{\frac{3k_BT}{m_{\text{gas}}}}$.
In addition, each individual molecule is pulled to the Earth by gravity. Heavier gasses, such as water, carbon dioxide, and oxygen, are pulled more than lighter gasses, such as hydrogen and helium. The escape velocity of the planet is given by $v_{\text{escape}}=\sqrt{\frac{2GM_{\text{planet}}}{R_{\text{planet}}}}$.
If a gas molecule has a high enough thermal energy, then if it is at the top of the atmosphere, it could fly off into space, the thermal motion overcoming gravity's pull. The lighter it is, the less thermal energy it needs to have. Of course, this all depends on probability and statistics, but, in general, if $v_{\text{gas}}\ge0.2 \times v_{\text{escape}}$, that species of gas will be reduced to 1/2 its initial amount after 1 billion years.

Solar wind consists of charged particles and high energy photons, which are deflected by a planet's magnetic field. However, in the case of a planet like Mars, without a magnetic field, the particles interact with the atmosphere. They tend to split molecules apart, resulting in lighter gasses (a process called "photodissociation"). These gasses, being bound less strongly by gravity, are more free to fly off into space under thermal motion. As more and more gas leaves the planet, the atmosphere becomes thinner and thinner until, ultimately, only the heavy gasses are left. In addition, when a molecule is split, the energy imparted to it by the impact may be enough to eject it from the atmosphere (a process called "sputtering").
Planets (and moons) that are closer to the sun are subject to more intense solar radiation, and also have higher atmospheric temperatures. This is why distant moons, such as Titan, have thick atmospheres of hydrocarbons. Planets close to the sun, such as Venus, can retain their atmospheres for a variety of reasons. Firstly, Venus's atmosphere is primarily carbon dioxide, which is much heavier than Hydrogen, and more difficult to split via photodissociation than water. Planets like Earth also have hydrogeological cycles which can recycle gas from rocks and water back into the atmosphere.
For more information on this, read up on Jeans Escape. A good set of notes for beginners can be found here.