Hello Cynthia, thank you very much for helping me and here is my sample data and my code. I first use proc summary to extract the column and calculate their total (b). Then I used them to calculate the new variable (c), and I used concatenating method to combine them (d). After all, I used proc report to make the output. But it turns out does not include my last raw (my handmade column sum and total rates, (c)). Since the total rates in last row are not the column sum, so I can not simply use summarize to make this problem. Thank you !!!! data a; input code type $ name $ total good bad good_rate bad_rate; datalines; 11 a apple 10 8 2 0.8 0.2 11 b apple 10 7 3 0.7 0.3 11 c apple 20 10 10 0.5 0.5 13 a banana 10 8 1 0.8 0.2 17 a orange 30 27 3 0.9 0.1 17 b orange 30 18 12 0.6 0.4 ; proc summary data = a; var total good bad; output out = b (drop = _type_ _freq_); sum = total good bad; run; data c; set b; name = 'Total' good_rate = round((good/total), .1); bad_rate = round((bad/total), .1); run; data d; set a c; run; proc report data = d; column _all_; define code / group; define type / display; define name / display; define total / display; define good / display; define bad / display; define good_rate / display; define bad_rate / display; run;
... View more