0

グループごとに、小計行から 1 を引いた次の proc レポートがあります。以下に示すレポートの例では、最初のグループの小計は実際には 2 ですが、代わりに 1 を表示しています。この部分は正常に動作します。

私の問題は、総計ラインにあります。すべての小計行の要約である必要がありますが、代わりにカウント列のすべてのデータを要約しています。たとえば、その下のレポートは 5 を示していますが、3 を表示する必要があります。これを達成する方法がわかりません。どんな助けでも大歓迎です...

コード:

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

    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}; 

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;

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

compute first_last;
if _break_ = 'FIRST_LAST' then
    first_last = 'SUBTOTAL';
else if _break_ = '_RBREAK_' then
    first_last = 'GRAND TOTAL';
endcomp;

    title; 
run;

レポートの例:

    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
4

2 に答える 2

0

obs の数を数え、それを合計数から差し引くことで、これを解決しました。

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;
于 2014-07-15T14:22:44.110 に答える