The SAS Output Delivery System and reporting techniques

Proc Report compute on last group by line

Frequent Contributor
Posts: 83

Proc Report compute on last group by line

I have the following example of data:

Clock Num     Date          In          Out          Turn      Hrs     Turn     Paycode               Amount    DAILY **Column I want to add

69900            3/3/14       7:34       17:33         

69900            3/3/14                                     2          9.5

69900            3/3/14                                                            2      CREWLEADER          1

69900            3/3/14                                                            2      PROD HRS                8

69900            3/3/14                                                            3      CREWLEADER          1

69900            3/3/14                                                            3      PROD HRS               1.5          9.5

The column titled Hrs; I want to SUM and display on the last line of data by Clock Num and Date.  Daily = sum(Hrs)

I have the following code and I am using proc report compute.  I am unsure how to display the total on the last line of data.

proc report data = test nowd;

column clock_num turn_dt in_tm out_tm hrs_turn_ident hrs_dec turn_ident pay_cd amt_dec daily;

define clock_num / group 'Clock Num';

define turn_dt / group 'Date' ;

define in_tm / display 'In';

define out_tm / display 'Out';

define hrs_turn_ident / display 'Turn';

define hrs_dec / display 'Hrs';

define turn_ident / display 'Turn';

define pay_cd / display 'Paycode';

define amt_dec / display 'Amount';

define daily / computed 'Daily';

define turn_dt / order;

break after turn_dt / ;

compute daily;




Posts: 8,819

Re: Proc Report compute on last group by line

It is not entirely clear to me why you want the total hours to appear on the last row of data. It is very hard to detect the last data row. You could get PROC REPORT to compute the value for you if you used a BREAK statement, but you'd have to change the usage of hrs_dec to SUM instead of DISPLAY. And the total of hrs_dec would appear in that column on a separate row.


Super User
Posts: 9,867

Re: Proc Report compute on last group by line

Why not do it in data step ?

data have;
input num date : mmddyy10. hrs ;
format date mmddyy10.;
1 3/3/14 .
1 3/3/14 9.5 
1 3/3/14 .
1 3/3/14 .
2 3/4/14 7.9
2 3/4/14 .
2 3/5/14 .
2 3/5/14 .
data have;
 set have;
 by num date;
 if then do;daily=s; s=.;end;
 drop s;

Xia Keshan

Ask a Question
Discussion stats
  • 2 replies
  • 3 in conversation