data test;
length ctr $25.;
infile datalines;
input ctr $ cnt cnt2;
return;
datalines;
4411 5 15
4455 15 66
4466 6 666
4477 11 42
;
run;
proc report = test nowd style(summary)=Header;
title 'test';
column ctr cnt cnt2 RTot PctTot;
define ctr /order order=data style (column)=Header ;
define cnt /sum f=comma6.;
define cnt2 /sum f=comma6.;
define PctTot/computed f=percent8.2;
define RTot /computed f=comma16. "Row Totals";
compute RTot;
RTot=sum(cnt.sum,cnt2.sum);/*row_tot*/
endcomp;
compute before;
sum=cnt.sum;
endcomp;
compute PctTot;
pcttot=cnt.sum/sum;
endcomp;
compute after;
ctr='Total';
endcomp;
rbreak after /summarize;
run;
It produces the results below. I want the PCTTOT to be a measure of the cnt2/RTOT so for the first entry it should be 15/20 = 0.75 or 75% So essentially I want to calculate at the row level across
ctr | cnt | cnt2 | Row Totals | PctTot |
---|---|---|---|---|
4411 | 5 | 15 | 20 | 13.51% |
4455 | 15 | 66 | 81 | 40.54% |
4466 | 6 | 666 | 672 | 16.22% |
4477 | 11 | 42 | 53 | 29.73% |
Total | 37 | 789 | 826 | 100.0% |
Please post code in a code box. Use the {I} or "running man" icon to open the box.
Your code as posted doesn't run as you are missing the data= on proc report;
Maybe:
proc report data = test nowd style(summary)=Header; title 'test'; column ctr cnt cnt2 RTot PctTot; define ctr /order order=data style (column)=Header ; define cnt /sum f=comma6.; define cnt2 /sum f=comma6.; define PctTot/computed f=percent8.2; define RTot /computed f=comma16. "Row Totals"; compute RTot; RTot=sum(cnt.sum,cnt2.sum);/*row_tot*/ endcomp; compute before; sum=cnt.sum; endcomp; compute PctTot; pcttot=_c3_ / _c4_; endcomp; compute after; ctr='Total'; endcomp; rbreak after /summarize; run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.