SUPPORT / SAMPLES & SAS NOTES
 

Support

Sample 33009: Creating a Top N Report

DetailsCodeOutputDownloadsAboutRate It
The Top N report is pervasive in our society. From the Billboard Top 100 to the New York Times Best Sellers list to the Forbes list of the 100 Richest Americans, the Top N list is a medium that we can all understand: which are the top “whatevers” that stand out from the rest?

Businesses rely on reports like these every day. It begins with what seems like a simple question. For example:

  • “Who are our top ten customers, measured by amount of sales?”
  • “Who are the ten most effective sales associates in each region?”
  • “Which are the five top-selling brands for each product family that we distribute?”

SAS offers many procedures that you can use to create reports like these. This example uses the following steps:

  • Use the MEANS procedure to summarize data, either over the entire data set or across a grouping variable by using the CLASS statement.
  • Use the SORT procedure to rank the summarized data, then use the DATA step to include only the top n values in the result set.
  • Use the REPORT procedure to create an easy-to-read listing report.
  • Use the GCHART procedure to create a simple bar chart that communicates the results in a visual way.

This example includes four SAS programs:

  • TopNCategories.sas – creates a Top N report for a column, stratified across a category variable.
  • TopNCategoryCount.sas – creates a variation of the first report that uses frequency count as the measure.
  • TopNStraight.sas – creates a simple Top N report for one column that uses one measure (sum or average).
  • TopNStraightCount.sas – creates a variation of the third report that uses frequency count as the measure.

This example also includes a custom task that you can use with SAS Enterprise Guide 4.1 and SAS Add-In 2.1 for Microsoft Office. The custom task offers a user interface that makes it easy to generate all of these types of reports without having to modify any SAS programs. The custom task is in the Downloads section of this example.

This sample was written by Chris Hemedinger.


These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.