Fix a smooth function $f:\mathbb{R}\to\mathbb{R}$. Do there exist real numbers $a<b$, an infinite set $S\subset (a, b)$ and an analytic function $g$ defined on $(a-\epsilon, b+\epsilon)$ for some $\epsilon>0$ such that $f|_S=g|_S$?
If $g$ is only required to be defined on $(a, b)$ the question has a positive answer. In fact, we can take any $(a, b)$ we like and set $g=f(a)+\mathrm{sin}(\frac{1}{x-a})$.
We can not require $g$ to be defined on all of $\mathbb{R}$ since we can take $f(x)=\mathrm{exp}(-\frac{1}{|x|})$ for $x\neq 0$ and $f(0)=0$. Then by the pigeonhole principle $S$ must contain infinitely many positive numbers or infinitely many negative numbers; in either case $g$ does not extend to $\mathbb{R}$. Coincidentally, this shows that an arbitrary $(a, b)$ won't do in the original problem.