An straightforward way to put exclusions into sums is by using KroneckerDelta
:
excl = {4, 9, 14};
Sum[
Times @@ (1 - Thread[KroneckerDelta[n, excl]]) r^(1 - l[n]) DD[n],
{n, 1, Infinity}
]
$$\sum _{n=1}^{\infty } \text{DD}(n)
(1-\delta _{4,n}) (1-\delta
_{9,n}) (1-\delta _{14,n})
r^{1-l(n)}$$
To show that this also works when the summand would otherwise be undefined, here is an example:
DD[n_] := 1/(n - 9)^2
Sum[
Times @@ (1 - Thread[KroneckerDelta[n, excl]]) DD[n], {n, 1,
Infinity}]
(* ==> (1021301 + 117600 Pi^2)/705600 *)
So the divergent term never gets evaluated because the KroneckerDelta
sets it to zero first.