@s_lassen wrote:
Yet another take on this.
The colon wildcard ,sum(of pop:), is the simplest, but it may not work if you have other variables that begin with POP.
The double dash approach ,sum(of pop--lastvar) only works if the POP variables are last in your input data.
A more safe approach may be this:
data want;
retain pop1-pop99 .;
set have;
sum=sum(of pop1-pop99);
run;
That way, all the variables will exist, and the order of the variables on the dataset or the names of other variables do not matter.
This is a good warning and a good solution, but if the user only started out with say POP1-POP59, they would now have 40 excess variables in the output dataset.
One might get around this by:
data want;
set have;
sum=sum(of pop1:, of pop2:, of pop3:, of pop4:, of pop5:, of pop6:, of pop7:, of pop8:, of pop9:);
run;
It's a bit wordy but:
It wouldn't include other variables with names like POP_US, POP_WORLD, etc.
It would sum up all the variables of interest, and
it wouldn't inadvertently create any extra variables in the output dataset.
... View more