Helen
Helen

Reputation: 617

proc summary with statistic "multiply"

Is it possible to make a new statistic with proc summary that multiplies every value in each column, for example instead of just mean? SAS is so rigid it makes me crazy.

data test;                                                
    input b c ;                                 
    datalines;                                                
    50 11                                       
    35 12                                        
    75 13                                       
    ;  

Desired output would be 50*35*75, and 11*12*13, and _FREQ (as is normal output in proc summary)

Upvotes: 0

Views: 395

Answers (1)

Reeza
Reeza

Reputation: 21294

This is an uncommon aggregate so you essentially need to roll your own. Since a data step loops this is easily accomplished using a RETAIN to keep value from row to row and outputting result at the last record.

 Data want;
   Set have end=eof;
   Retain prod_b prod_c;
   prod_b = prod_b * b;
   prod_c = prod_c * c;
   Freq= _n_;
 If eof then OUTPUT; 
  Keep prod: freq;
 Run;

Upvotes: 1

Related Questions