Xanax is not intended to treat insomnia, its main effect is to relieve anxiety. Taking it without a doctor's prescription can be dangerous, especially because of the risk of addiction. It is better to discuss your sleep problems with a doctor to find the right remedy.