Using Proc SQL to summarize tables into groupings


/ Published in: SAS
Save to your folder(s)

Using Proc SQL summarize the table sashelp.shoes grouping on


Copy this code and paste it in your HTML
  1. /*Taken from thread http://groups.google.com/group/comp.soft-sys.sas/browse_thread/thread/8cdec58cd0846e29?hl=en*/
  2.  
  3. /*Method 1*/
  4. proc sql feedback;
  5. *describe table dictionary.columns;
  6. select
  7. catx(' ','Sum(',name,') as',
  8. Name,ifc(not missing(format),cats('format=',format),' '))
  9. into :sumlist separated by ', '
  10. from dictionary.columns
  11. where libname eq 'SASHELP' and memname eq 'SHOES' and type eqt 'n'
  12. ;
  13. %put NOTE: &numlist;
  14. select region, product, &sumlist
  15. from sashelp.shoes
  16. group by region, product
  17. ;
  18. quit;
  19. run;
  20.  
  21.  
  22. /*Method 2*/
  23. proc sql;
  24. select region, product, sum(stores) as sumstores, sum(sales) as sumsales,
  25. sum(inventory) as suminventory, sum(returns) as
  26. sumreturns from sashelp.shoes
  27. group by region, product;
  28. quit;

URL: http://jaredprins.squarespace.com/blog/2008/5/11/use-proc-sql-to-summarize-tables-into-groupings.html

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.