« Merge datasets with unlike variable names | Main | Top 10 Reasons Why You Wait at the Doctor's Office »

Use Proc SQL to summarize tables into groupings

Here are 2 methods of using Proc SQL ot summarize tables into groupings.  In this case we use the SasHelp.Shoes dataset.  You can view the same code on my snippet repository.

 /*Method 1*/

proc sql feedback;
   *describe table dictionary.columns;
   select
      catx(' ','Sum(',name,') as',
               Name,ifc(not missing(format),cats('format=',format),' '))
      into :sumlist separated by ', '
      from dictionary.columns
      where libname eq 'SASHELP' and memname eq 'SHOES' and type eqt 'n'
      ;
   %put NOTE: &numlist;
   select region, product, &sumlist
      from sashelp.shoes
      group by region, product;
quit;


/*Method 1*/

proc sql;
  select region, product, sum(stores) as sumstores, sum(sales) as sumsales,
  sum(inventory) as suminventory, sum(returns) as
  sumreturns from sashelp.shoes
  group by region, product;
quit;

 

Posted on Saturday, May 3, 2008 by Registered CommenterJared in | CommentsPost a Comment

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>