SAS/GRAPH: Beyond the Basics
Total Page:16
File Type:pdf, Size:1020Kb
The correct bibliographic citation for this manual is as follows: Allison, Robert. 2012. SAS/GRAPH®: Beyond the Basics. Cary, NC: SAS Institute Inc. SAS/GRAPH®: Beyond the Basics Copyright © 2012, SAS Institute Inc., Cary, NC, USA ISBN 978-1-61290-201-2 (electronic book) ISBN 978-1-60764-989-2 All rights reserved. Produced in the United States of America. For a hard-copy book: No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, or otherwise, without the prior written permission of the publisher, SAS Institute Inc. For a Web download or e-book: Your use of this publication shall be governed by the terms established by the vendor at the time you acquire this publication. The scanning, uploading, and distribution of this book via the Internet or any other means without the permission of the publisher is illegal and punishable by law. Please purchase only authorized electronic editions and do not participate in or encourage electronic piracy of copyrighted materials. Your support of others’ rights is appreciated. U.S. Government Restricted Rights Notice: Use, duplication, or disclosure of this software and related documentation by the U.S. government is subject to the Agreement with SAS Institute and the restrictions set forth in FAR 52.227-19, Commercial Computer Software-Restricted Rights (June 1987). SAS Institute Inc., SAS Campus Drive, Cary, North Carolina 27513-2414 1st printing, February 2012 SAS® Publishing provides a complete selection of books and electronic products to help customers use SAS software to its fullest potential. For more information about our e-books, e-learning products, CDs, and hard-copy books, visit the SAS Publishing Web site at support.sas.com/publishing or call 1-800-727-3228. SAS® and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Other brand and product names are registered trademarks or trademarks of their respective companies. Contents Acknowledgements ....................................................................................... v Preface .................................................................................................... vii Example 1 Bar with Annotated Marker ........................................................ 1 Example 2 Using PROC GREPLAY For Custom Dashboard Layout ........................... 7 Example 3 Paneling Multiple Graphs on a Page ............................................. 17 Example 4 Using an Image As Part of the Graph ............................................ 27 Example 5 Customizing a Map ................................................................. 33 Example 6 Overlay G3D Surfaces .............................................................. 41 Example 7 Adding Border Space ............................................................... 47 Example 8 Determine Customers Within Map Borders ..................................... 55 Example 9 Determine Customers Within Circular Radius .................................. 63 Example 10 Custom Box Plots ................................................................. 65 Example 11 Using Company Logos in Graphs ................................................ 71 Example 12 Annotated Map Borders .......................................................... 77 Example 13 Population Tree Charts ........................................................... 87 Example 14 Sparkline Table .................................................................... 97 Example 15 Custom Waterfall Chart ........................................................ 109 Example 16 Plotting Data on Floor Plans .................................................. 117 Example 17 Custom Calendar Chart ......................................................... 127 Example 18 Fancy Line Graph with Broken Axis ........................................... 141 Example 19 Drill-down Link to an HTML Anchor ........................................... 149 Example 20 Time Series “Strip Plot” ....................................................... 157 Example 21 GIF Animation .................................................................... 163 Example 22 Using SAS/IntrNet with Graphs ................................................ 169 Example 23 Plotting Coordinates on a Map ................................................ 175 Example 24 Plotting Coverage Areas on a Map ........................................... 185 Example 25 Plotting Multiple Graphs on the Same Page ................................ 193 Example 26 Grand Finale: An Advanced Dashboard ...................................... 201 Now What ....................................................................................... 225 Index............................................................................................. 227 iv Acknowledgements So, how did I become a SAS/GRAPH expert and end up writing this book? There are many people who played a role in that, but I’d specifically like to thank the following: Dr. Moon Suh, my advisor at NCSU, who first introduced me to SAS software, encouraged me to become a “data meister,” and challenged me to learn how to create analytic graphics. Dr. David Dickey, my time series professor at NCSU, who “showed me the light” with his tricky SAS examples in class and at user conferences, and showed me that anything is possible with SAS/GRAPH. Mike Zdeb, who has worked on joint conference papers with me, and who sends me “ideas” and “challenges” on an almost weekly basis so that I don’t run out of ideas. Stephen Few, who gave me the opportunity to win the DM Review dashboard contest and who also allows me to bounce ideas off him. He keeps me pointed in the right direction in pursuit of “graphical excellence.” SAS Institute, for providing SAS software to NCSU (for free), where I used it for my dissertation project. As the saying goes, “When your only tool is a hammer, every problem looks like a nail.” SAS software was (and still is) a superb hammer! Meg Pounds, who was my boss for 10 years, and who gave me the flexibility to spend my testing time experimenting with the SAS/GRAPH software, learning and inventing new things to do with it, and working with the developers to request new features that enable us to create even better custom graphs. Robert Dolan, who played a major role in adding several of the underlying features that I use such as anti-aliasing, support for more than 16 million colors, and transparency. Kathleen Ramage, who has continued to support and enhance the traditional SAS/GRAPH procedures such as PROC GCHART, by adding the key features I need in order to create the perfect graph. And my Mom, who let me draw graphics on the attic walls and encouraged me to design posters for 4-H demonstrations and a slew of other things growing up. vi SAS/GRAPH: Beyond the Basics I would also like to thank the following technical reviewers and others who helped out behind the scenes: Steve England - Technical Reviewer Marcia Surratt - Technical Reviewer Mike Zdeb -Technical Reviewer Brad Kellam - Copy Editor Marchellina Waugh - Cover Design Jennifer Dilley - Graphics Denise Jones - Production Specialist Stacey Hamilton - Marketing Specialist Mary Beth Steinbach - Managing Editor George McDaniel – Development Editor Preface A wise man once said: “A motivated SAS/GRAPH programmer can create just about any graph.” In this book, I try to give you the knowledge and inspiration to be that programmer. These days, anybody can create a simple graph. Many companies provide software with a simple GUI (Graphical User Interface) that enables users to point-and-click their way through a gallery of graphs, select which variables to plot, and produce a mediocre graph. Given how easy it is to make them, you might ask, "How can I make my graphs stand out?" A lot of people fall into the trap of trying to make their graphs stand out by being fancier. They add bright colors, three-dimensional effects, images in the background, and sometimes make the charts fade-in, spring-up, or oscillate before coming to a rest where you can finally read them. But fancier is not necessarily better, and in the case of graphs, such fancy additions usually make the graph more difficult to read and quickly comprehend, so making the graph fancier can actually make the graph worse rather than better. I encourage you to make your graphs stand out by being better, rather than fancier. And by better, I mean graphs that show the data more clearly, and make it easier for people to look at the graph and quickly answer the questions the graph was created to answer in the first place. And in order to do that, you will need to learn to customize your graphs. That is where SAS/GRAPH comes in. Whereas most software provides only a GUI interface that enables you to create the graphs that are pre-programmed, SAS/GRAPH provides a programming framework that enables you to customize every aspect of the graphs. It even enables you to create totally new and unique graphs. Very few people take the time to learn how to create better graphs through customization, and therefore knowing how to do this will give you a great competitive advantage. Purpose of This Book The purpose of this book is to go way beyond the basics, and teach you how to create your own custom graphs, not just to modify the look of the graphs, but to create your own graphs with totally