Use Proc SQL to summarize tables into groupings
Saturday, May 3, 2008
Jared in SAS

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;

 

Article originally appeared on jaredprins (http://jaredprins.squarespace.com/).
See website for complete article licensing information.