我有一个数据集,其中有2列,分别对应于当月和上个月。我只需要对这两列执行求和运算。问题在于,每个月的更新都会更改列的名称。如何在SAS中自动执行此过程?
当前数据集
ID 9月10月
1 23 12
2 31 19
3 37 21
下个月数据集
ID Oct 11月
1 17 21
2 12 23
3 55 21
我如何自动计算每个月两列的总和?
发布于 2013-11-07 19:49:55
如果要聚合列,请执行以下操作:
proc sql noprint;
select
cat('sum(', trim(name), ') as month', put(monotonic(), 1. -L)) into :sum_statement separated by ', '
from dictionary.columns
where libname = 'WORK'
and memname = 'SOMETABLE'
and upcase(name) ne 'ID'
;
quit;
%put &sum_statement;
proc sql;
create table sum as
select &sum_statement from WORK.SOMETABLE
;
quit;
https://stackoverflow.com/questions/19834545
复制相似问题