data have;
length ctr $25.;
input ctr cnt cnt2;
return;
datalines;
4544 2 1
4544 3 1
4465 10 1
4465 5 1
4475 1 0
4475 2 0
4475 3 1
4476 5 2
4476 6 1
;
run;
proc report data = have nowd style(summary)=Header;
column ctr cnt cnt2 /*rtot*/;
define ctr /order order=data style (column)=Header "Center";
define cnt /sum f=comma6. "Total Opened";
define cnt2 /sum f=comma6. "No Activity";
/*define RTot /computed f=comma16. "Row Totals";*/
/*compute RTot;
/*RTot=sum(cnt.sum,cnt2.sum);/*row_tot*/
endcomp;
compute before;
sum=cnt.sum;
sum=cnt2.sum;
endcomp;
compute after;
ctr='Grand Total';
endcomp;
rbreak after /summarize;
run;
It produces this output (copy also enclosed)
Have | ||
Center | Total Opened | No Activity |
4544 | 2 | 1 |
3 | 1 | |
4465 | 10 | 1 |
5 | 1 | |
4475 | 1 | 0 |
2 | 0 | |
3 | 1 | |
4476 | 5 | 2 |
6 | 1 | |
Grand Total
|
37 | 8 |
I want to produce the following with totals and percentages by Center and then Grand totals(info highlighted in yellow)
Want | |||
Center | Total Opened | No Activity | %Inactive |
4544 | 2 | 1 | |
3 | 1 | ||
Total-4544 | 5 | 2 | 40 |
4465 | 10 | 1 | |
5 | 1 | ||
Total-4465 | 15 | 2 | 13.33333 |
4475 | 1 | 0 | |
2 | 0 | ||
3 | 1 | ||
Total-4475 | 5 | 1 | 20 |
4476 | 5 | 2 | |
6 | 1 | ||
Total-4476 | 11 | 3 | 27.27273 |
Grand Total | 37 | 8 |
Hello,
Check this out:
proc report data = have nowd style(summary)=Header;
column ctr cnt cnt2 /*rtot*/ pct_inactive;
define ctr /order order=data style (column)=Header "Center";
define cnt /sum f=comma6. "Total Opened";
define cnt2 /sum f=comma6. "No Activity";
define pct_inactive/ computed format=percent8.2 '%Inactive';
compute after ctr;
ctr='Sub Total';
pct_inactive=cnt2.sum/cnt.sum;
endcomp;
compute after;
ctr='Grand Total';
endcomp;
break after ctr / summarize ;
rbreak after /summarize;
run;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: