Summing along row - sum and arrays.
Using the sum function:
data want;
set dt00;
sum=sum(x, y);
run;
You could also use sum=sum(of _numeric_); - this will sum all numeric columns in case too many to list.
Using arrays:
data want;
set dt00;
array s {*} _numeric_;
sum=sum(of s[*]);
run;
Summing along column - here we are only interested in the total sum of the column, so we select the last row. You can do this with the combination of the end= option in the set statement and the if statement.
data want;
set dt00 end=eof;
sum_x + x;
sum_y + y;
if eof then output;
keep sum:;
run;
In case you have a lot of columns I would advise you to compute the columns total using other SAS procedures (e.g. using the means procedure).
proc means data=dt00 noprint;
var _numeric_;
output out=want(drop=_type_ _freq_) sum= / autoname;
run;
Summing all cells - here we use the same trick as for summing along column as we are only interesting in the total sum of all cell.
data want;
set dt00 end=eof;
sum + x + y;
if eof then output;
keep sum;
run;
The sum statement sum + x + y implies that the sum variable is automatically retained and that all missing values are considered as 0.
Put simply, this is the equivalent of
data want;
set dt00 end=eof;
retain sum;
sum = sum(sum,x,y);
if eof then output;
keep sum;
run;