More than likely if you went to the ER with an anxiety attack, they would give you an injection of Ativan which pretty much stops the attack in it's tracks. (Xanax is not available in injectable form, hence the use of Ativan)
Since most anxiety/panic attacks don't usually last more than 15-20 minutes and it takes both Ativan and Xanax at least 30 minutes to get into your blood stream, taking either medication once an attack has begun is rather futile. It will help calm you down when the attack is over, but it will not stop an attack that has begun. (Of course the exception to this is an injection of Ativan, but they aren't going to send any of us home with a vial and spikes!)
While these medications are similar, they do have some differences and it's pretty much up to the prescribing doctor which one he sends you home with. If you are not use to Xanax, it can be very sedating and depending on how long you sleep, I'm surprised you wake up still feeling somewhat anxious.
I am not a doctor and therefore cannot recommend one med over the other. That is a discussion you need to have with your doctor.
The next time you find yourself in the ER with an anxiety attack, ask the doctor for a recommendation for a therapist or psychiatrist for your anxiety. The meds are only going to mask the symptoms and do nothing for the root cause of your anxiety. Benzos are not meds you want to fool around with any longer than is absolutely necessary.
Peace
Greenlydia