PROC TABULATE WITH TOTAL

时间:2014-03-04 15:32:35

标签: sas

我正在使用proc制表进行报告,但无法在报告中添加总计。

实施例

+--------+------+----------+--------+---+---+---+
|  Shop  | Year |  Month   | Family | A | B | C |
+--------+------+----------+--------+---+---+---+
| raoas  | 2006 | january  | TA12   | 5 | 6 | 0 |
| taba   | 2008 | january  | TS01   | 0 | 1 | 1 |
| suptop | 2008 | april    | TZ05   | 0 | 0 | 1 |
| taba   | 2006 | December | TA12   | 5 | 6 | 0 |
| raoas  | 2008 | january  | TA15   | 0 | 2 | 0 |
| sup    | 2008 | april    | TQ05   | 0 | 1 | 1 |
+--------+------+----------+--------+---+---+---+

proc tabulate data=REPORTDATA_T6 format=12.;
            CLASS YEAR;
            var A  C;
            table  (A  C)*SUM='',YEAR=''
            /box = 'YEAR';
        TITLE 'FORECAST SUMMARY';
  run;

输出

YEAR    2006 2008 2009
A       800 766 813
C       854 832 812

我尝试了...表(A C)*总和,年份...它将总结多年,但我想要年。 我尝试了所有可能的方法并尝试了...表(A C)*总和,年。它将给出观察次数,即N .. Thanx JON CLEMENTS但我不想在表中添加TOTAL VARIABLE,becoz这是一个样本数据,但变量的数量超过10,有时我需要更改变量,所以,每次我都不想添加新变量作为总数。

1 个答案:

答案 0 :(得分:1)

我不确定是否可以仅使用原始数据一步完成您想要的操作。关键字ALL仅适用于总结CLASS变量的类别,但您想要总结两个不同的变量

但是使用临时步骤很容易,创建数据集,其中A,B,C变量将成为一个变量的类别:

data REPORTDATA_T6;
    input Shop $ Year Month $ Family $ A B C;
datalines;
raoas 2006 january TA12 5 6 0
taba 2008 january TS01 0 1 1
suptop 2008 april TZ05  0 0  1
taba 2006 December TA12 5 6 0
raoas 2008 january TA15 0 2 0
sup 2008 april TQ05 0 1 1
;
run;
proc sort data=REPORTDATA_T6; by Shop Year Month Family; run;

proc transpose data=REPORTDATA_T6 out=REPORTDATA_T6_long;
    var A B C;
    by Shop Year Month Family;
run;

proc tabulate data=REPORTDATA_T6_long;
    class _NAME_  YEAR;
    var COL1;
    table  (_NAME_ all)*COL1=' '*SUM=' ', YEAR=' '
    /box = 'YEAR';
    TITLE 'FORECAST SUMMARY';
run;