DATA Step, Macro, Functions and more

Proc tabulate - summing a sum

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 8
Accepted Solution

Proc tabulate - summing a sum

[ Edited ]

 

I created some dummy data

 

Data crop;
input season $ farm $ food $ amount;
datalines;
Fall'13 Florida apples 23
Spr'14 Florida apples 18
Sumr'14  Florida apples 19
Fall'13 Alabama apples 23
Spr'14 Alabama apples 25
Sumr'14  Alabama apples 24
Fall'13 Georgia apples 12
Spr'14 Georgia apples 14
Sumr'14  Georgia apples 11
Fall'13 Florida oranges 50
Spr'14 Florida oranges 48
Sumr'14  Florida oranges 32
Fall'13 Alabama oranges 10
Spr'14 Alabama oranges 9
Sumr'14  Alabama oranges 8
Fall'13 Georgia oranges 26
Spr'14 Georgia oranges 18
Sumr'14  Georgia oranges 11
;
run;

proc tabulate data=crop;
class season farm food;
var amount;
tables food*amount, farm*(season);
run;

 

and it made

 

   farm        
   Alabama  Florida  Georgia  
   season  season  season  
   Fall'13Spr'14Sumr'14Fall'13Spr'14Sumr'14Fall'13Spr'14Sumr'14
food           
applesamountSum232524231819121411
orangesamountSum10985048322618

11

 

 

 

 

 

I want to create a new row that sums  each column

 

   farm        
   Alabama  Florida  Georgia  
   season  season  season  
   Fall'13Spr'14Sumr'14Fall'13Spr'14Sumr'14Fall'13Spr'14Sumr'14
food           
applesamountSum232524231819121411
orangesamountSum1098504832261811
Total  3334367366413832

22

 

 

 

However if I try using the all statement

 

proc tabulate data=crop;
class season farm food;
var amount;
tables food*amount all, farm*(season);
run;

it produces

 

   farm        
   Alabama  Florida  Georgia  
   season  season  season  
   Fall'13Spr'14Sumr'14Fall'13Spr'14Sumr'14Fall'13Spr'14Sumr'14
food           
applesamountSum232524231819121411
orangesamountSum1098504832261811
All N222222222

 

Any help would be appreciated


Accepted Solutions
Solution
‎02-15-2017 03:37 PM
Respected Advisor
Posts: 4,927

Re: Proc tabulate - summing a sum

Try instead:

 

proc tabulate data=crop;
class season farm food;
var amount;
tables (food all)*amount, farm*season;
run;
PG

View solution in original post


All Replies
Solution
‎02-15-2017 03:37 PM
Respected Advisor
Posts: 4,927

Re: Proc tabulate - summing a sum

Try instead:

 

proc tabulate data=crop;
class season farm food;
var amount;
tables (food all)*amount, farm*season;
run;
PG
Occasional Contributor
Posts: 8

Re: Proc tabulate - summing a sum

Thanks I thought I tried that, but I guess I did not. Smiley Happy

That's what happens when you stare at a problem too long.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 123 views
  • 0 likes
  • 2 in conversation