在SAS中返回列和的数据集

在SAS中返回列和的数据集,sas,Sas,从2001年到2014年,我有很多数据集,如下所示。每年存储在一个文件中,yxxx.sas7bdat ID Weight X1 X2 X3 1 100 1 2 4 2 300 4 3 4 我需要创建一个数据集,其中每年都有X列的(加权)和 X1 X2 X3 Year 10 20 30 2014 40 15 20 2013 我很乐意将其实现到宏中,但我不确定如何隔离列和,以及如何将结果附加在一起(proc append?) 编辑:包括一次尝试 %macro final_

从2001年到2014年,我有很多数据集,如下所示。每年存储在一个文件中,
yxxx.sas7bdat

ID Weight X1 X2 X3
1  100    1  2  4
2  300    4  3  4
我需要创建一个数据集,其中每年都有
X
列的(加权)和

X1 X2 X3 Year
10 20 30 2014
40 15 20 2013
我很乐意将其实现到宏中,但我不确定如何隔离列和,以及如何将结果附加在一起(proc append?)

编辑:包括一次尝试

%macro final_dataset;

%do i = 2001 %to 2014;

/*Code here which enables me to get the column sums I am interested in.*/

proc means data = y&i;
 weight = weight;
 X1 = SUM X1;
 X2 = SUM X2;
 X3 = SUM X3;
 OUTPUT OUT = sums&i;
run;

data final;
 set final sums&i;
run;

%end;
%mend;
编辑:另一次尝试

%macro final_dataset;

%do i = 2001 %to 2014;

/*Code here which enables me to get the column sums I am interested in.*/

proc means data = y&i SUM;
 weight = weight;
 var X1 X2 X3;
 OUTPUT OUT = sums&i;
run;

data final;
 set final sums&i;
run;

%end;
%mend;
编辑:最终版本

%macro final_dataset;

%do i = 2001 %to 2014;

/*Code here which enables me to get the column sums I am interested in.*/

proc means data = y&i SUM NOPRINT;
 weight = weight;
 var X1 X2 X3;
 OUTPUT OUT = sums&i sum(X1 X2 X3) = X1 X2 X3;
run;

data final;
 set final sums&i;
run;

%end;
%mend;

这可能就是我要做的,将所有数据集附加在一起,然后运行一个过程。你没有提到数据集有多大,但我假设数据较小

data combined;
length source year $50.;
set y2001-y2014 indsname=source;
*you can tweak this variable so it looks how you want it to;
year=source;
run;


proc means data=combined noprint nway;
class year;
var x1 x2 x3;
output out=want sum= ;
run;

发布您迄今为止尝试过的内容。最简单的方法可能是将所有数据集附加在一起,然后在该数据集上使用proc means。不需要宏。