In totally real number fields, we characterize the rings of S-integers (obtained by inverting a rational integer m) such that all their totally positive elements are represented as a sum of squares. We further obtain partial answers to the question: when are all the totally positive algebraic integers that are divisible by m represented as a sum of squares?