SAS Proc报告-基于小计的总计?

SAS Proc报告-基于小计的总计?,sas,proc-report,Sas,Proc Report,我有以下proc报告,其中我取小计行,并从中减去每组1。因此,对于下面列出的示例报告,第一组实际上有一个小计2,但我让它显示为1。这部分很好用 我的问题在于总路线。我需要它是所有小计行的汇总,但它是汇总第个计数列中的所有数据。例如,下面的报告显示5,但我需要它显示3。我不知道如何做到这一点。任何帮助都将不胜感激 代码: 示例报告: first_last maj min count something1 aaaaaaa bb 1

我有以下proc报告,其中我取小计行,并从中减去每组1。因此,对于下面列出的示例报告,第一组实际上有一个小计2,但我让它显示为1。这部分很好用

我的问题在于总路线。我需要它是所有小计行的汇总,但它是汇总第个计数列中的所有数据。例如,下面的报告显示5,但我需要它显示3。我不知道如何做到这一点。任何帮助都将不胜感激

代码:

示例报告:

    first_last    maj         min   count
    something1    aaaaaaa     bb      1
                  aaaaaaa     cc      1
    subtotal                          1

    something2    bbbbbbb     bb      1
                  bbbbbbb     cc      1
                  bbbbbbb     dd      1
    subtotal                          2 

    grand total                       5

我将小计的总和存储在一个新变量中,并显示它,而不是自动汇总。这似乎是最简单的展示方式。我不知道有没有一种简单的方法可以在自动摘要过程中实现这一点-SAS并不完全希望您按照上面的方式来做事情(老实说,我很惊讶它能如此工作)。

通过计算OB的数量并从总数中减去OB来解决这一问题

proc report data = mnr missing nowindows;
    columns     first_last
                maj
                mnr
                count
                obs
                gt
                ;

    define first_last / group
                style(header)={font=('calibri',10pt,bold) just=c}
                style(column)={font=('calibri',10pt) just=c cellwidth=2.0in};
    define maj / display
                style(header)={font=('calibri',10pt,bold) just=c}
                style(column)={font=('calibri',10pt) just=c cellwidth=1.0in}; 
    define mnr / display
                style(header)={font=('calibri',10pt,bold) just=c}
                style(column)={font=('calibri',10pt) just=c cellwidth=1.0in}; 
    define count / analysis sum 
                style(header)={font=('calibri',10pt,bold) just=c}
                style(column)={font=('calibri',10pt) just=c cellwidth=1.0in}; 
    define obs /  computed noprint;
    define gt /  computed noprint;


break after first_last / summarize style=[foreground=black just=c font=('calibri',10pt,bold)];

compute after first_last / style=[background=light grey];
line  ' ';
endcomp;

compute count;
if _break_ = 'FIRST_LAST' then
    count.sum = count.sum - 1;
endcomp; 

compute first_last;
if _break_ = 'FIRST_LAST' then
    first_last = 'SUBTOTAL';
endcomp;

compute obs;
if _break_ = 'FIRST_LAST' then
    count+1;
    obs=count;
endcomp;

compute gt;
gt = count.sum - obs;
endcomp;

compute after / style=[just=r font=('calibri',10pt,bold)];
line 'GRAND TOTAL' gt;
endcomp;

    title; 
run;

这听起来是个好主意,但我不知道如何得到小计的总和。我尝试了一些方法,但最终得到的总金额与以前相同。您需要创建一个新变量,然后在计算小计-1的计算块中,将新的小计金额添加到新变量中。
proc report data = mnr missing nowindows;
    columns     first_last
                maj
                mnr
                count
                obs
                gt
                ;

    define first_last / group
                style(header)={font=('calibri',10pt,bold) just=c}
                style(column)={font=('calibri',10pt) just=c cellwidth=2.0in};
    define maj / display
                style(header)={font=('calibri',10pt,bold) just=c}
                style(column)={font=('calibri',10pt) just=c cellwidth=1.0in}; 
    define mnr / display
                style(header)={font=('calibri',10pt,bold) just=c}
                style(column)={font=('calibri',10pt) just=c cellwidth=1.0in}; 
    define count / analysis sum 
                style(header)={font=('calibri',10pt,bold) just=c}
                style(column)={font=('calibri',10pt) just=c cellwidth=1.0in}; 
    define obs /  computed noprint;
    define gt /  computed noprint;


break after first_last / summarize style=[foreground=black just=c font=('calibri',10pt,bold)];

compute after first_last / style=[background=light grey];
line  ' ';
endcomp;

compute count;
if _break_ = 'FIRST_LAST' then
    count.sum = count.sum - 1;
endcomp; 

compute first_last;
if _break_ = 'FIRST_LAST' then
    first_last = 'SUBTOTAL';
endcomp;

compute obs;
if _break_ = 'FIRST_LAST' then
    count+1;
    obs=count;
endcomp;

compute gt;
gt = count.sum - obs;
endcomp;

compute after / style=[just=r font=('calibri',10pt,bold)];
line 'GRAND TOTAL' gt;
endcomp;

    title; 
run;