If $S$ is closed, and $A$ is suitably continuous, you can apply Whitney extension theorem to extend $f$ to be real analytic outside $S$.
If $S$ is not closed, then in a neighborhood of $\bar{S}\setminus S$ you can easily construct an example of a function that is $C^\infty$ on $S$ but cannot be continuously extended to $\bar{S}$ (think $1/|x|$ on the punctured disk).
Since there are some confusion about Whitney's theorem in the comments, let me add a few lines about it here.
In the context of the current problem posed, Whitney's theorem says:
Preamble. Let $S$ be a closed subset of $\mathbb{R}^m$. Let $f:S\to \mathbb{R}^n$ be a continuous function. Let $A$ be a continuous function on $S$ taking values in the space of $n\times m$ matrices. Define the function $R: S\times S\to \mathbb{R}^n$ by
$$ R(x,y) = f(y) - f(x) - A(x) \cdot (y-x). $$
Theorem. If for every $\epsilon > 0$, there exists a $\delta > 0$ such that whenever $|x-y| < \delta$ we have $|R(x,y)| < \epsilon |x-y|$, then there exists a function $F:\mathbb{R}^m \to \mathbb{R}^n$ that is continuously differentiable, such that
- $F = f$ on the set $S$
- $\nabla F = A$ on the set $S$
- $F$ is real analytic on $\mathbb{R}^m \setminus S$.
Basically, the theorem says that if you have a continuous $f$, and a continuous "putative derivative" $A$ (since $S$ is only assumed to be closed, given a point $x\in S$ it may not be possible to define the derivative of $f$ [this is the case when $x$ is not in the interior of $S$]), then provided the "putative remainder term" $R$ (remainder in the sense of Taylor polynomials) behaves like a remainder term (that when $x,y$ approaches each other it should go to zero fast enough), then you can extend $f$ to a continuously differentiable function $F$.