We prove that each semialgebraic subset of R^n of positive codimension can be locally approximated of any order by means of an algebraic set of the same dimension. As a consequence of previous results, algebraic approximation preserving dimension holds also for semianalytic sets