You have the right idea of how these spectral lamps work. In a sodium lamp, electrons excite sodium atoms from the ground state to excited states. These states exist at higher energies than the ground states, but are unstable. Therefore, these excited sodium atoms drop down to lower energy states very quickly. When they do, they emit a photon at the energy equal to the change of energy of the electron; these photons are what we observe. Since they only occur at certain energies (and frequencies and wavelengths), we observe a spectral line pattern.
These patterns are based on the physics of one atom by itself. When there are two atoms very close to each other, they interact, via the electric force. That changes the energies that the different states could have just a little bit. The energy of an emitted photon is exactly equal to this change of energy, so instead of having one energy at which many photons are emitted, you have a range of energies through which these photons are emitted. Then, instead of seeing the sharp spectral lines that you are used to seeing, you would see blurred lines. For this reason, low-pressure sodium lamps are used.
The answer to your second question is yes! Imagine there is some background source, like a regular incandescent light bulb, behind your sodium lamp. The incandescent bulb emits visible light at all wavelengths. The sodium in between you and the lamp absorbs photons at certain wavelengths (the same ones it was emitting at earlier!) while the electrons in the sodium are excited to higher energy levels. This would cause an absorption spectrum of sodium in the light you observe from the incandescent bulb.
Interestingly, astronomers use exactly this technique to study gases in the vacuum of space, in between stars in our galaxy and in between galaxies in our universe. Light from distant stars and galaxies act like the incandescent bulb in our previous example: this light has certain absorption lines from its travels, which can be used to determine what gases are in the intergalactic and interstellar media and in what quantities.
Thanks for the questions!
(published on 05/24/11)