How to Make an Impressive Map of the United States with SAS/Graph for Beginners Sharon Avrunin-Becker, Westat, Rockville, MD

Similar documents
Panelists. Patrick Michael. Darryl M. Bloodworth. Michael J. Zylstra. James C. Green

DEPARTMENT OF HOUSING AND URBAN DEVELOPMENT. [Docket No. FR-6090-N-01]

2018 NSP Student Leader Contact Form

A New Method of Using Polytomous Independent Variables with Many Levels for the Binary Outcome of Big Data Analysis

Telecommunications and Internet Access By Schools & School Districts

Figure 1 Map of US Coast Guard Districts... 2 Figure 2 CGD Zip File Size... 3 Figure 3 NOAA Zip File Size By State...

CostQuest Associates, Inc.

Accommodating Broadband Infrastructure on Highway Rights-of-Way. Broadband Technology Opportunities Program (BTOP)

Fall 2007, Final Exam, Data Structures and Algorithms

MAKING MONEY FROM YOUR UN-USED CALLS. Connecting People Already on the Phone with Political Polls and Research Surveys. Scott Richards CEO

Ocean Express Procedure: Quote and Bind Renewal Cargo

CSE 781 Data Base Management Systems, Summer 09 ORACLE PROJECT

Distracted Driving- A Review of Relevant Research and Latest Findings

The Lincoln National Life Insurance Company Universal Life Portfolio

B.2 Measures of Central Tendency and Dispersion

State IT in Tough Times: Strategies and Trends for Cost Control and Efficiency

NSA s Centers of Academic Excellence in Cyber Security

THE LINEAR PROBABILITY MODEL: USING LEAST SQUARES TO ESTIMATE A REGRESSION EQUATION WITH A DICHOTOMOUS DEPENDENT VARIABLE

Global Forum 2007 Venice

Silicosis Prevalence Among Medicare Beneficiaries,

Department of Business and Information Technology College of Applied Science and Technology The University of Akron

Post Graduation Survey Results 2015 College of Engineering Information Networking Institute INFORMATION NETWORKING Master of Science

2018 Supply Cheat Sheet MA/PDP/MAPD

Tina Ladabouche. GenCyber Program Manager

IT Modernization in State Government Drivers, Challenges and Successes. Bo Reese State Chief Information Officer, Oklahoma NASCIO President

MERGING DATAFRAMES WITH PANDAS. Appending & concatenating Series

DSC 201: Data Analysis & Visualization

Name: Business Name: Business Address: Street Address. Business Address: City ST Zip Code. Home Address: Street Address

CMPE 180A Data Structures and Algorithms in C++ Spring 2018

AASHTO s National Transportation Product Evaluation Program

Team Members. When viewing this job aid electronically, click within the Contents to advance to desired page. Introduction... 2

Presented on July 24, 2018

Best Practices in Rapid Deployment of PI Infrastructure and Integration with OEM Supplied SCADA Systems

Moonv6 Update NANOG 34

A Capabilities Presentation

Sideseadmed (IRT0040) loeng 4/2012. Avo

Charter EZPort User Guide

Contact Center Compliance Webinar Bringing you the ANSWERS you need about compliance in your call center.

Presentation to NANC. January 22, 2003

Prizm. manufactured by. White s Electronics, Inc Pleasant Valley Road Sweet Home, OR USA. Visit our site on the World Wide Web

Fly over, drill down, and explore

ACCESS PROCESS FOR CENTRAL OFFICE ACCESS

Touch Input. CSE 510 Christian Holz Microsoft Research February 11, 2016

INTRODUCTION TO THE SAS ANNOTATE FACILITY

Presentation Outline. Effective Survey Sampling of Rare Subgroups Probability-Based Sampling Using Split-Frames with Listed Households

Homework Assignment #5

Amy Schick NHTSA, Occupant Protection Division April 7, 2011

2015 DISTRACTED DRIVING ENFORCEMENT APRIL 10-15, 2015

Configuring Oracle GoldenGate OGG 11gR2 local integrated capture and using OGG for mapping and transformations

Geographic Accuracy of Cell Phone RDD Sample Selected by Area Code versus Wire Center

PulseNet Updates: Transitioning to WGS for Reference Testing and Surveillance

DTFH61-13-C Addressing Challenges for Automation in Highway Construction

The Outlook for U.S. Manufacturing

State HIE Strategic and Operational Plan Emerging Models. February 16, 2011

The Basics of Map Creation with SAS/GRAPH. Mike Zdeb School of Public Health Rensselaer, NY

PharmaSUG 2013 CC26 Automating the Labeling of X- Axis Sanjiv Ramalingam, Vertex Pharmaceuticals, Inc., Cambridge, MA

Creating Maps in SAS/GRAPH

Put Your Data on the Map: Using the GEOCODE and GMAP Procedures to Create Bubble Maps in SAS

CIS 467/602-01: Data Visualization

It s Not All Relative: SAS/Graph Annotate Coordinate Systems

Strengthening connections today, while building for tomorrow. Wireless broadband, small cells and 5G

Custom Map Displays Created with SAS/GRAPH Procedures and the Annotate Facility Debra Miller, National Park Service, Denver, CO

Controlling Titles. Purpose: This chapter demonstrates how to control various characteristics of the titles in your graphs.

What Did You Learn? Key Terms. Key Concepts. 68 Chapter P Prerequisites

Coders' Corner. Paper ABSTRACT GLOBAL STATEMENTS INTRODUCTION

Effective Forecast Visualization With SAS/GRAPH Samuel T. Croker, Lexington, SC

Free or Reduced Air from Select Gateways for 1st & 2nd guest on reservation

Selling Compellent Hardware: Controllers, Drives, Switches and HBAs Chad Thibodeau

Data Annotations in Clinical Trial Graphs Sudhir Singh, i3 Statprobe, Cary, NC

Expanding Transmission Capacity: Options and Implications. What role does renewable energy play in driving transmission expansion?

Steve Stark Sales Executive Newcastle

Tips to Customize SAS/GRAPH... for Reluctant Beginners et al. Claudine Lougee, Dualenic, LLC, Glen Allen, VA

Today s Lecture. Factors & Sampling. Quick Review of Last Week s Computational Concepts. Numbers we Understand. 1. A little bit about Factors

Multiple Forest Plots and the SAS System

Using a Probabilistic Model to Assist Merging of Large-scale Administrative Records

Increase uptime with a faster, more reliable, connection

Real World Algorithms: A Beginners Guide Errata to the First Printing

Recovery Auditor for CMS

Unit 7 Day 5 Graph Theory. Section 5.1 and 5.2

PharmaSUG Paper TT10 Creating a Customized Graph for Adverse Event Incidence and Duration Sanjiv Ramalingam, Octagon Research Solutions Inc.

ARE WE HEADED INTO A RECESSION?

ASR Contact and Escalation Lists

Jurisdictional Guidelines for Accepting a UCC Record Presented for Filing 2010 Amendments & the 2011 IACA Forms

GREMOVE, Reassign, and let s GMAP! A SAS Trick for Generating Contiguous Map Boundaries for Market-Level Research

The GANNO Procedure. Overview CHAPTER 12

On All Forms. Financing Statement (Form UCC1) Statutory, MARS or Other Regulatory Authority to Deviate

Checkpoint Learning Premier CPE package

2013 Product Catalog. Quality, affordable tax preparation solutions for professionals Preparer s 1040 Bundle... $579

Geospatial Analysis with PROC GMAP

OPERATOR CERTIFICATION

Checkpoint Learning Premier Plus CPE package

USING PROC GMAP AND DRILL-DOWN GRAPHICS FOR DATA QUALITY ASSURANCE Meghan Arbogast, Computer Sciences Corporation, Corvallis, OR

The Plot Thickens from PLOT to GPLOT

Panasonic Certification Training January 21-25, 2019

Medium voltage Marketing contacts

The Altice Business. Carrier Advantage

Pro look sports football guide

National Continuity Programs

Data Visualization (CIS/DSC 468)

PharmaSUG 2012 Paper CC13

Transcription:

Paper RIV-27 How to Make an Impressive Map of the United States with SAS/Graph for Beginners Sharon Avrunin-Becker, Westat, Rockville, MD ABSTRACT Have you ever been given a map downloaded from the internet and asked to reproduce the same thing using SAS complete with labels and annotations? As you stare at all the previously written, brilliant SAS/Graph conference papers, you start feeling completely overwhelmed. The papers assume you already know how to get started and you feel like a clueless clone not understanding what you are missing. This paper will walk you through the steps to getting started with your map and how to add colors and annotations that will not only impress your manager, but most importantly yourself that you could do it too! INTRODUCTION In great anticipation of the 7 th Star Wars movie release, a fictional researcher has decided he wants to track characteristics of loyal Star Wars fans. He has developed a survey and has posted it on various fan based sites. He wants to track how many fans have completed the survey across the United States and has divided the states into four regions in hopes of identifying where the most loyal fans live. Figure 1. Example of a simple map not done with SAS HOW TO GET STARTED The first time I tried to create a map using SAS I read some incredible papers on the topic, but I had a hard time getting past the first step. I knew I had a SAS/GRAPH license, but I didn t know how to access any of the maps. These maps are important because they contain the information for SAS to know where to draw the boundary lines. I finally noticed over in the Explorer window under Libraries a directory I had never clicked on before called Maps. The SAS datasets located here are what you need to be able to tell SAS what kind of map you are trying to draw. Figure 2. Location of Maps directory 1

GET COUNTS BY STATE Now that we know where to find the information for the maps, let s get the data ready to be used. First, we are going to get counts by states and attach the region number to each dataset. Of course, experienced programmers will be able to do all this in one easy PROC SQL but for the beginners I broke it down into two easy steps to better understand what is happening. /* Step 1 getting counts by region and adding region number */ %macro doit (reg= ) proc sql create table x&reg as select state, count(*) as stcnt from soutregion where newreg = &reg group by state quit data xx&reg set x&reg region = &reg %mend doit %doit (reg=1) %doit (reg=2) %doit (reg=3) %doit (reg=4) /* Step 2 - set your datasets back together */ data allx set xx1 xx2 xx3 xx4 GET COUNTS BY REGION Let s also grab counts by region which we will use later. proc sql create table z as select region, sum(stcnt) as stcntx from allx group by region quit FINISH GETTING DATA READY The next step is to get your data looking a bit better for displaying on a map. First, we will add the variable statecode so we can merge this data in with the maps datasets. Then we will add a zero (0) to any states where a survey may not have been completed. Finally, we will add a new variable called text which contains the state abbreviation and the number of surveys completed for that state. 2

data allx2 length STATECODE $2. set allx STATECODE = state if stcnt =. then stcnt = 0 text=cats(state) ' (' cats(stcnt) ')' RUN BEFORE ADDING TEXT AND LEGENDS Before we start adding in text and labels let s take a quick look at what the code and map looks like at this point if we plan to shade our map by regions. The map dataset US will be used to define the longitude and latitude lines for each state. The CHORO option below specifies the variable we want to use to determine the shadings in the choropleth map. proc gmap data=allx2 map=maps.us id STATECODE choro region quit Figure 3. Output from PROC GMAP READY TO USE THE MAP DATA We are finally ready to start using the maps datasets. First we will sort the datasets so they can be merged together. We will need to first merge in US2 which contains the FIPS codes for the states (the variable for the FIPS codes is called STATE). proc sort data=allx2 out=sallx2(drop=state) by STATECODE proc sort data=maps.us2 out=sus2(keep=state STATECODE) by STATECODE data mapfips merge sallx2 sus2 by STATECODE 3

THEN WE WILL NEED TO MERGE IN WITH USCENTER TO GET THE PROJECTED LONGITUDES AND latitudes for the radians (these variable are named X and Y), so SAS knows where to place the text. proc sort data=mapfips out=smapfips by STATE proc sort data=maps.uscenter out=suscenter(keep=state X Y) nodupkey by STATE data mapfips2 merge smapfips (in=a) suscenter (in=b) by STATE if a This data step defines where and when the labels will be placed (in this case the labels will be centered on each states X Y axis after the map boundaries are drawn). data stlabel length function $ 8 position $ 1 text $ 20 style $ 30 set mapfips2 retain xsys ysys '2' hsys '3' position '5' function 'label' size 1.40 color 'black' style "'Tahoma/bo'" when 'a' Finally we run the same code as before with the annotation specified proc gmap data=allx2 map=maps.us id STATECODE choro region / annotate=stlabel quit 4

Figure 4. Output from PROC GPLOT with annotation specified SPECIFYING COLORS If you would like to switch your colors you can do this by adding in a pattern statement. The v in the code below is the value statement specifying you want a solid pattern. THE COLORS ARE SPECIFIED pattern1 v=ms c=yellow pattern2 v=ms c=lightgreen pattern3 v=ms c=lightpurple pattern4 v=ms c=lightblue Figure 5. Output from PROC GMAP with color specified 5

ADDING IN A LEGEND As nice as this table looks, you have no idea what these colors represent. Now is the time to add in a legend. The legend has lots of options associated with it. You can assign where on the graph you want to display your legend, you can specify the labels on the values, and you can also have a frame around your legend. You can even add in macro variables to display totals. Don t forget that the legend statement needs to be added to your PROC GMAP code for it to be displayed. THE SIMPLE LEGEND SPECIFICS LEGEND1 LABEL=(HEIGHT=1 POSITION=TOP JUSTIFY=CENTER "Total Star Wars Fans Across All States") VALUE=(HEIGHT=1 "R2D2 Region" "Ewok Region" "Chewbacca Region" "Yoda Region") ACROSS=1 DOWN=4 POSITION = (bottom outside right) FRAME MODE=PROTECT offset=(-25 pct) proc gmap data=allx2 map=maps.us id STATECODE choro region / annotate=stlabel legend=legend1 quit Figure 6. Output from PROC GMAP with legend ADDING IN MACRO VARIABLES DATA _null_ SET z if region = 1 then CALL SYMPUTX('reg1tot',stcntx) if region = 2 then CALL SYMPUTX('reg2tot',stcntx) if region = 3 then CALL SYMPUTX('reg3tot',stcntx) if region = 4 then CALL SYMPUTX('reg4tot',stcntx) RUN 6

LEGEND1 LABEL=(HEIGHT=1 POSITION=TOP JUSTIFY=CENTER "Total Star Wars Fans Across All States") VALUE=(HEIGHT=1 "R2D2 Region (&reg1tot.)" "Ewok Region (&reg2tot.)" "Chewbacca Region (&reg3tot.)" "Yoda Region (&reg4tot.)") ACROSS=1 DOWN=6 POSITION = (Bottom outside right) FRAME MODE=PROTECT offset=(-22 pct) Figure 7. Output from PROC GPLOT with totals specified ADDING IN MAIN POINTS OF INTEREST Next we want to see if survey returns were higher in states where a Star Wars experience or convention had occurred within the past 20 years. To do this we select the cities we want from the USCity dataset in the Maps directory. Since some city names may be located in more than one state, you can also specify the state you are interested in. Then you can specify the color, size, position, and shape of your overlay city markers. Then merge it back in to the dataset with your previous state definitions. data citystar length function color $ 8 position $ 1 text $ 20 style $ 30 retain xsys ysys '2' hsys '3' when 'a' set maps.uscity(keep=x y city statecode state) if (STATECODE='FL' and city='orlando') or (STATECODE='CA' and city='anaheim') or (STATECODE='CO' and city='denver') or (STATECODE='IN' and city='indianapolis') or (STATECODE='CA' and city='los Angeles') or (STATECODE='TX' and city='san Antonio') /* Create the observation for a star */ function='symbol' style='marker' text='z' color='red' size=1.25 output /* Create the observation for a city */ function='label' style="'albany AMT/bold'" text=city color='red' size=1.5 position='2' output data stlabel2 7

set citystar stlabel (drop=stcnt region) Figure 8. Output from PROC GMAP with target cities defined ADDING IN TITLES Titles and footnotes are added the same way in SAS as they always are by using an appropriate title or footnote statement title j=c h=2 "Star Wars Is More Than A Movie, It's An Obsession" footnote j=l h=1 "Where will you be December 18, 2015?" Star Wars Is More Than A Movie, It's An Obsession WA (131) MT (22) ND (3) ME (8) OR (132) MN (386) VT (8) ID (28) SD (3) WI (41) NY (433) NH (42) MA (26) WY (75) NV (25) Denver UT (20) CA (90) CO (11) NE (9) KS (71) IA (23) MO (103) MI (16) PA (87) OH (31) Indianapolis IL (34) IN (5) WV (25) VA (47) KY (106) RI (29) CT (114) NJ (133) DE (2) MD (42) Los Angeles An ah ei m AZ (151) NM (40) OK (46) AR (48) TN (177) SC (30) NC (101) MS (69) AL (527) GA (197) TX (720) LA (57) AK (203) San Antonio Total Star Wars Fans Across All States Orlando FL (762) HI (111) R2D2 Region Ewok Region Chewbacca Region Yoda Region Where will you be December 18, 2015? Figure 9. Output from PROC GMAP with a title and footnote 8

CONCLUSION This paper touched on some basic code to get the beginner SAS programmer started on creating maps. Sometimes the information out there can be so thorough but complex that it is hard to break down the first few steps to even know how to begin programming. Once you have the basic understanding of how the code comes together you can turn to other papers and start creating even more complex maps. REFERENCES Zdeb, M. The Basics of Map Creation with SAS/GRAPH, SUGI 29 Eberhart, M. Make the Map You Want with PROC GMAP and the Annotate Facility, NESUG 2008 ACKNOWLEDGMENTS Many thanks to Michael Raithel, Rick Mitchell, and Sarah Woodruff. CONTACT INFORMATION Your comments and questions are valued and encouraged. Contact the author at: Sharon Avrunin-Becker Westat 1650 Research Blvd. WB432 Rockville, MD 20850 Work Phone: (301) 738-8384 Email: SharonAvruninBecker@westat.com DISCLAIMER The contents of this paper are the work of the author and do not necessarily represent the opinions, recommendations, or practices of Westat. 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 trademarks of their respective companies. 9