Ever since I started learning formal logic I've had these kind of doubts: Is analysis ever studied in a completely axiomatic/formal proofy way?
What I mean is, given a set of axioms and inference rules, to prove things via formal proofs.
Example:
Let $f: \Bbb R\to \Bbb R: x\mapsto x$.
Theorem. $f(a)=0\iff a = 0$.
Proof:
Assume $f(a)=0$. \begin{eqnarray*} \forall x\, f(x)&=&x \quad \text{Definition of $f$.}\tag 1\\ f(a)&=&0\quad \text{Hypothesis.}\tag 2\\ f(a)&=&a\quad \text{Instantiation of 1.}\tag 3\\ a&=&0\quad \text{Substitution Axiom (Lines 2, 3).}\tag 4 \end{eqnarray*} Thus we have that $f(a)=0\implies a=0$, the other arrow is pretty trivial, as this one was, but this was just an example, as is the "substitution axiom".
Is analysis studied or treated in this way in any book you know?
Your question is a very good one. It is my personal opinion that textbooks can be improved a lot by making the logical structure of proofs clearer, because many students do not have the proper grasp of logic to construct the structure on their own, not to say verify with absolute confidence that the proof is correct. It is definitely possible to do proofs in analysis (and of course every other branch of mathematics) in a manner that you suggest, and probably the most suitable format for such kind of presentation is Fitch-style natural deduction, where assumptions are clearly shown via indentation by putting the statements that depend on it under the assumption. Same for universally quantified variables. This is directly analogous with contexts in programming languages for if-statements and for-loops.
That said, formal reasoning constitutes only one part of mathematics, and an equally important part is the intuition about the mathematical structure itself. A good exposition of a mathematical theorem must not only give a sufficiently formal proof to establish its validity but also give a good explanation of the techniques used in the proof, including the intuitive ideas in and an outline of the proof, which would be obscured by a purely symbolic proof. Of course, yet another aspect that must not be neglected is the motivation for the theorem itself.
In any case, you might be interested in reading about Automath, which was one of the first formal proof systems amenable to computer verification, developed by De Bruijn (somehow few people know about his contribution here!), and an entire textbook Foundations of Analysis by Edmund Landau had been translated into Automath by L.S. van Benthem Jutting and computer-checked. Largely forgotten, Automath heavily influenced later proof systems including Mizar, which has one of the largest libraries and is still actively used. One other major proof system is Coq, which has a rather different underlying formal system based on type theory instead of set theory. But actually type theory is actually closer to how most mathematicians think, and proofs that are verified in Coq's constructive logic translate naturally and easily to programs that witness the theorem's correctness, which notion is captured by the Brouwer-Heyting-Kolmogorov interpretation.