Help using Base SAS procedures

Summarize using Proc Report when there are 3 or more groups

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

Summarize using Proc Report when there are 3 or more groups

Hi All, 

 

May I check if I m allowed to use Proc Report to summarize multiple groups? 

 

for eg. if i have region,country, state, zip-code, different expenses as my variables. 

 

I would want would the report to have a listing of zip-code and then the data would be further sum up by state, country & region (all in one report)

 

Would appreciate your reply. Thanks!

 


Accepted Solutions
Solution
‎04-01-2018 11:51 AM
SAS Super FREQ
Posts: 9,371

Re: Summarize using Proc Report when there are 3 or more groups

Hi, I guess I don't understand exactly what you mean when you say: "a listing of zip-code and then the data would be further sum up by state, country & region (all in one report)" -- it's hard to visualize the report you want from this description.

  Yes, PROC REPORT can produce summaries on multiple items. So can PROC MEANS, so can PROC TABULATE.

  What code have you tried and what is the ultimate destination for the report (RTF, PDF, HTML?)

  I have an example of multiple summaries using SASHELP.PRDSALE. Here is what it looks like for 1 country (CANADA), 2 regions (EAST and WEST), 2 divisions (CONSUMER and EDUCATION) and 5 products. This same type of summary also appears for the other 2 countries, GERMANY and U.S.A. -- but for space, I'm only showing one country here. You'd have to run the code below to see the report for all 3 countries in HTML format.

use_report_summary.png

 

Here's the complete code that produced the report:

ods html path='c:\temp' file='sum_prdsale.html';
title;
proc report data=sashelp.prdsale spanrows;
  column country region division product actual predict;
  define country / group;
  define region / group;
  define division / group;
  define product / group;
  define actual / sum;
  define predict / sum;
  break after country / summarize style={background=lightyellow};
  break after region / summarize style={background=lightgreen};
  break after division / summarize style={background=verylightblue};
  rbreak after / summarize style=Header;
  compute after country;
    country = 'C-tot';
	line ' ';
  endcomp;
  compute after region;
    region = 'R-tot';
  endcomp;
  compute after division;
    division = 'D-tot';
  endcomp;
  compute after;
    Country = 'Gr-tot';
  endcomp;
run;
ods html close;



Cynthia

View solution in original post


All Replies
Solution
‎04-01-2018 11:51 AM
SAS Super FREQ
Posts: 9,371

Re: Summarize using Proc Report when there are 3 or more groups

Hi, I guess I don't understand exactly what you mean when you say: "a listing of zip-code and then the data would be further sum up by state, country & region (all in one report)" -- it's hard to visualize the report you want from this description.

  Yes, PROC REPORT can produce summaries on multiple items. So can PROC MEANS, so can PROC TABULATE.

  What code have you tried and what is the ultimate destination for the report (RTF, PDF, HTML?)

  I have an example of multiple summaries using SASHELP.PRDSALE. Here is what it looks like for 1 country (CANADA), 2 regions (EAST and WEST), 2 divisions (CONSUMER and EDUCATION) and 5 products. This same type of summary also appears for the other 2 countries, GERMANY and U.S.A. -- but for space, I'm only showing one country here. You'd have to run the code below to see the report for all 3 countries in HTML format.

use_report_summary.png

 

Here's the complete code that produced the report:

ods html path='c:\temp' file='sum_prdsale.html';
title;
proc report data=sashelp.prdsale spanrows;
  column country region division product actual predict;
  define country / group;
  define region / group;
  define division / group;
  define product / group;
  define actual / sum;
  define predict / sum;
  break after country / summarize style={background=lightyellow};
  break after region / summarize style={background=lightgreen};
  break after division / summarize style={background=verylightblue};
  rbreak after / summarize style=Header;
  compute after country;
    country = 'C-tot';
	line ' ';
  endcomp;
  compute after region;
    region = 'R-tot';
  endcomp;
  compute after division;
    division = 'D-tot';
  endcomp;
  compute after;
    Country = 'Gr-tot';
  endcomp;
run;
ods html close;



Cynthia

New Contributor
Posts: 4

Re: Summarize using Proc Report when there are 3 or more groups

Posted in reply to Cynthia_sas
Yes, this is what i am looking for. Thanks a lot!
☑ This topic is solved.

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

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