BookmarkSubscribeRSS Feed
Q1983
Lapis Lazuli | Level 10

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"

 

1 REPLY 1
Cynthia_sas
Diamond | Level 26

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):

totals_with_length.png


Cynthia

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 7586 views
  • 0 likes
  • 2 in conversation