This is inspired by answers in the other linked threads. You can let $f(S') = \sum_{x_j \in S'} 2^{j-1}$.
If you let your set only contain powers of 2, i.e. $S = \{ 1, 2, 4, 8, \ldots , 2^i\}$, then $f(S') = \sum_{x_j \in S'} x_j$, the sum of all numbers in S'$S'$.
Note that this is the same as interpreting $S'$ as a length $i$ binary number where the $j$th bit is 1 if $x_j \in S'$ and 0 otherwise. Note that there are $2^i$ different subsets of $S$ so you need a binary number of length at least $i$ to be able to represent all possible subsets.