Sas 处理向表中添加汇总行的更干净的方法?

Sas 处理向表中添加汇总行的更干净的方法?,sas,Sas,我有一个只有5个变量的数据集,有两个因变量。我的目标是让这个数据集附加额外的行,其中TOTAL作为自变量的值,而因变量的值也相应地改变 要对单个自变量执行此操作不是问题,我将按照以下思路执行: proc sql; create table want as select "TOTAL" as independent_var1, independent_var2, ... independent_var5, sum(dependent_1) as dependent_1, sum(dependent

我有一个只有5个变量的数据集,有两个因变量。我的目标是让这个数据集附加额外的行,其中TOTAL作为自变量的值,而因变量的值也相应地改变

要对单个自变量执行此操作不是问题,我将按照以下思路执行:

proc sql;
create table want as
select "TOTAL" as independent_var1,
independent_var2,
...
independent_var5,
sum(dependent_1) as dependent_1,
sum(dependent_2) as dependent_2
from have
group by independent_var1,...,independent_var5;
quit;
然后以您选择的任何方式附加原始数据集。然而,我想要上面的x5(对于每个自变量),然后再针对5个自变量的总/非总的每个可能组合。我不知道有多少数据集是从我的头上掉下来的…但这是一个相当可观的数量

所以到目前为止,我提出的最佳策略是使用上面的宏代码生成所有可能的总计/非总计的表组合,但似乎SAS可能有更好的方法,可能隐藏在一个我从未听说过的深奥的过程步骤中

--

尝试使用三个自变量和一个因变量显示示例:

Ind1|2|3|Dependent1
0 0 0 1
0 0 1 3
0 1 0 5
0 1 1 7
预期的产出将是:

0 0 ALL 4
0 1 ALL 12
0 ALL 0 6
0 ALL 1 10
ALL 0 0 1
ALL 0 1 3
ALL 1 0 5
ALL 1 1 7
0 ALL ALL 16
ALL 0 ALL 4
ALL 1 ALL 12
ALL ALL 0 6
ALL ALL 1 10
ALL ALL ALL 16
0 0 0 1
0 0 1 3
0 1 0 5
0 1 1 7

我可能忘记了一些组合,但这应该有助于理解这一点。

PROC意味着应该为您轻松地完成这一点。您需要清理输出,以使其与您想要的完全匹配(示例中的INDx=“ALL”缺少),否则它将正确完成计算

data have;
input Ind1 Ind2 Ind3 Dependent1;
datalines;
0 0 0 1
0 0 1 3
0 1 0 5
0 1 1 7
;;;;
run;

proc means data=have;
class ind1 ind2 ind3;
var dependent1;
output out=want sum=;
run;

你有没有理由不使用
PROC MEANS
PROC tablate
,这两种方法听起来都很好?也许一个小例子,有几个IVs和DVs,20行左右的文字来显示“have”和“want”会很有帮助。添加了一个小例子。我从未以这种方式使用过proc TABLATE;我会试着调查一下,看看能不能让它工作。看起来不错!我有几个问题要问,但可能已经够复杂了,他们应该提出自己的问题。谢谢,伙计