data test;
infile datalines;
input Year $ Dept1N Dept2N ;
return;
datalines;
2014 203382 1560000
2014 850000 1650000
2014 950000 850666
2015 750000 2650448
2015 12200 2006000
2015 8500 1600500
;
run;
/* Initial output
Year Dept1N Dept2N
2014 203382 1560000
2014 850000 1650000
2014 950000 850666
2015 750000 2650448
2015 12200 2006000
2015 8500 1600500*/
proc report = test;
title 'My Title';
columns Year Dept1N Dept2N RTot;
define year /group "Year ";
define Dept1N /sum "Dep1";
define Dept2N /sum "Dept2";
define RTot /computed f=comma16.2 "Row Totals";
compute RTot;
RTot=sum(Dept1N.sum,Dept2N.sum);/*row_tot*/
endcomp;
compute after;
year = 'Grand Total'; /*column or grand total*/
endcomp;
rbreak after /summarize;
run;
I am attempting to get the row grand-total (RTot) and the bottom line grand-total.
When I run the code I only get the total of the first instance.
In addition "Grand Total" is cut off to "Grand Tot"
Hi:
The quickest thing for you to do to fix Grand Total being truncated is to add a LENGTH statement to make year a bigger length. You need 11 characters to display Grand Total and PROC REPORT will use the length of YEAR for the display.
So do this:
length year $11;
before your INFILE statement.
As for your issue, I don't know what you mean by "I only get the total of the first instance." When I run your code, adding only the LENGTH statement, this is what I get #1. When I change the usage of YEAR to ORDER, then I get report #2 (I also added a break after YEAR to report #2):
Cynthia
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.