SAS Find Averages Over Multiple Datasets
I have several datasets, each with the same structure, and I would like to find the average of the values in each cell in the table.
eg. Let's say I have three tables, each with 3 rows (AC) and 2 columns (1-2), how can I calculate the average of these cells?
1 2 1 2 1 2
A 2 1 A 0 1 A 4 1
B 9 0 B 0 2 B 0 1
C 1 5 C 2 2 C 3 2
So the result is:
1 2
A 2 1
B 3 1
C 2 3
source to share
Concatenate datasets together, then use PROC (such as TOOLS OR SUMMARY) to calculate the average.
Assuming that your tables are called table1
, table2
, table3
and values A
to C
are in the variable name GROUP
, and the numerical values VAL1
andVAL2
data master; set table1-table3; run; proc summary data = master nway; class GROUP; var VAL1 VAL2; output out = averages (drop = _ :) mean =; run; proc print; run;
If the original datasets are large, consider creating master
as a view instead of the dataset:
data master / view = master; set table1-table3; run; ...
source to share