Lesson 13 More SGPLOT examples MAP Plotting Questions.

Slides:



Advertisements
Similar presentations
Statistical Methods Lynne Stokes Department of Statistical Science Lecture 7: Introduction to SAS Programming Language.
Advertisements

Today: Run SAS programs on Saturn (UNIX tutorial) Runs SAS programs on the PC.
Graphing With Excel Presented by Frank H. Osborne, Ph. D. © 2008 ID 2950 Technology and the Young Child.
Lesson 13 Another MACRO Example MAP Plotting. Macro Example Goal of Macro named Summary: For a given dataset give summary statistics using PROC CONTENTS,
Section 5: Graphs in Science
SAS Lecture 5 – Some regression procedures Aidan McDermott, April 25, 2005.
Copyright ©: SAMSUNG & Samsung Hope for Youth. All rights reserved Tutorials Software: Building apps Suitable for: Advanced.
Graphs in Science You Can Do It!!!.
Lesson 4: Graphing A Magically Delicious Activity.
Introduction to SAS BIO 226 – Spring Outline Windows and common rules Getting the data –The PRINT and CONTENT Procedures Manipulating the data.
1 Experimental Statistics - week 4 Chapter 8: 1-factor ANOVA models Using SAS.
Introduction to PROC GMap Presentation by Andrea Boan BMTRY 789.
Copyright © 2008 SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks.
SAS Mapping functionality to measure and present the Veracity of Location Data.
Graphing In Science BRAINSTORM Why is it important for scientists to organize their data? List as many ways as you can that scientists organize information.
Advanced Stata Workshop FHSS Research Support Center.
The Guide to Great Graphs Ten things every graph needs! Or… Ten things we hate about graphs!
1 Data Manipulation (with SQL) HRP223 – 2010 October 13, 2010 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This.
Lesson 6 - Topics Reading SAS datasets Subsetting SAS datasets Merging SAS datasets.
Chapter 22: Using Best Practices 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Lecture 3 Topic - Descriptive Procedures Programs 3-4 LSB 4:1-4.4; 4:9:4:11; 8:1-8:5; 5:1-5.2.
Requirements of a good GRAPH. GRAPH  Title (usually “dependent” vs. “independent”)  Go Big (cover at least ½ the page in both directions) This increases.
Chapter One, Section 5: Graphs in Science
Chapter 4 concerns various SAS procedures (PROCs). Every PROC operates on: –the most recently created dataset –all the observations –all the appropriate.
MASUG September 15, Agenda  Guest Introductions  John Boling – SAS inSchool  Tim Garton – Health Forecasts  Announcements  Tips & Tricks 
Lesson 8 - Topics Creating SAS datasets from procedures Using ODS and data steps to make reports Using PROC RANK Programs in course notes LSB 4:11;5:3.
Lesson 12 More SGPLOT examples Exporting data Macro variables Table Generation - PROC TABULATE Miscellaneous Topics.
Computing with SAS Software A SAS program consists of SAS statements. 1. The DATA step consists of SAS statements that define your data and create a SAS.
SAS ® is a very powerful tool when producing Graphics. A single graphical data step can easily create a Kaplan Meier Plot, but there is no single graphical.
SAS/GRAPH The Basics. Today’s Topics GOPTIONS GPLOT GCHART GCONTOUR G3D.
Welcome This is a document to explains the chosen concept to the animator. This will take you through a 5 section process to provide the necessary details.
Lesson 2 Topic - Reading in data Programs 1 and 2 in course notes –Chapter 2 (Little SAS Book)
SAS Programming Training Instructor:Greg Grandits TA: Textbooks:The Little SAS Book, 5th Edition Applied Statistics and the SAS Programming Language, 5.
CMS SAS Users Group Conference Learn more about THE POWER TO KNOW ® October 17, 2011 PROC GMAP, HTML and You Thomas Kornfield, CMS.
Based on Learning SAS by Example: A Programmer’s Guide Chapters 1 & 2
Thinking about Graphs The Grammar of Graphics and SAS.
Teacher Page Objective: The students will Compare Maps of voting patterns or political boundaries to make inferences about distribution of political power.
Contemporary Reading Habits Assignment Who’s reading what? Let’s find out!
Using Excel graphing functions Mr. Lesser Do Now Compare the two graphs below. Fill out the similarities and differences chart on your paper. Then.
New NWS Online Spot Program
Chapter 3: Getting Started with Tasks
Session 1 Retrieving Data From a Single Table
Introduction to Graphing in SAS
AP CSP: Cleaning Data & Creating Summary Tables
Add More Zing to your Dashboards – Creating Zing Plot Gadgets
Applied Business Forecasting and Regression Analysis
Guilford County SciVis V105.01
Lesson 2 Topic - Reading raw data into SAS
Lesson 6 - Topics Formatting Output Working with Dates
Forms on Demand for OMR (and scan from image)
Displaying and Describing Categorical Data
Lesson 3 Overview Descriptive Procedures Controlling SAS Output
Chapter 8: ODS Graphics ODS graphics were not available prior to SAS 9.2 They have been implemented across a wide range of procedures Functionality isn’t.
Prepared by Kimberly Sayre and Jinbo Bi
Lesson 9 - Topics Restructuring datasets LSB: 6:14
Unit 1 Most common: Line Graph
Lesson 8 - Topics Creating SAS datasets from procedures
Lesson 11 - Topics Statistical procedures: PROC LOGIST, REG
The Fundamentals of Mapping
Lesson 7 - Topics Reading SAS data sets
Graphing Notes.
3 Iterative Processing.
Introduction to DATA Step Programming: SAS Basics II
SAS Programming Training
Lecture 2 Topics - Descriptive Procedures
Working With Dates: Dates Come in Many Ways
Welcome 1 This is a document to explains the chosen concept to the animator. This will take you through a 5 section process to provide the necessary details.
WSAQDW planning documents
Graphs in Science p. 34.
Lecture 2 Topics - Descriptive Procedures
Presentation transcript:

Lesson 13 More SGPLOT examples MAP Plotting Questions

* How to start a SAS program; * Starting with raw (text based) data ; data tomhs; infile ‘/folders/myfolders/tomhs.dat’; input statement with variables and formats; * Add new variables here; run; * Starting with SAS dataset; libname t ‘/folders/myfolders/’; set t.tomhs; If you want to connect the points with a step-function then use the STEP statement. We saw this in the example of generating a life-table curve.

Note: Second question only answered if first question is answered yes. * Coding for smoker (0/1); if eversmk = 2 then smoker = 0; else smoker = 2-nowsmk; Did you ever smoke cigarettes? 1 = yes, 2= no Do you now smoke cigarettes? 1 = yes, 2= no Var: eversmk Var: nowsmk Two question were asked in TOMHS related to cigarette smoking; the first was “Have you ever smoked cigarettes” and if “yes” then “Do you currently smoke cigarettes” We want a variable to indicate current smoking status that includes the never smokers. We can get that with the if-then-else statement shown here. If the variable EVERSMK equals 2 (never smoker) than set the (new) variable CURRSMK to 2, otherwise set CURRSMK to the variable NOWSMK. See if you can follow the logic for the different possible answers to the two questions. We now have our outcome variable defined: variable CURRSMK, = to 1 for current smokers and = 2 for current non-smokers. Note: Second question only answered if first question is answered yes.

SCATTER vs SERIES vs REG vs STEP Obs trt month cd4 1 1 0 102 2 1 1 177 3 1 2 192 4 1 3 195 5 1 6 217 6 1 9 232 7 1 12 252 8 1 15 270 9 1 18 287 10 1 21 305 11 1 24 323 12 1 27 337 13 1 30 343 14 1 33 360 15 1 36 376 16 2 0 102 17 2 1 184 18 2 2 194 19 2 3 202 20 2 6 223 21 2 9 249 22 2 12 273 23 2 15 299 24 2 18 323 25 2 21 339 26 2 24 363 27 2 27 386 28 2 30 392 29 2 33 394 30 2 36 418 Want to plot mean CD4 levels over time for each of two groups. Here is the data we will use to illustrate the various line-plots you can generate with PROC SGPLOT. The data is mean CD4 counts by treatment group and months after starting medication for HIV.

* Scatter Plot for 2 groups; proc sgplot; xaxis label = 'Months After Start of Therapy' values=(0 to 36 by 6); yaxis label = 'Mean CD4 Level'; title 'Mean CD4 After Start of Therapy by Treatment Type'; scatter x=month y=cd4/group=trt ; format trt trtF.; label trt = 'Treatment Group'; run; The first line plot you can generate is a scatter plot using the SCATTER statement. You simple use the keyword SCATTER followed by the X and Y variables to be plotted. We then add the GROUP option which tells SAS to display the points separately by treatment group. We use the x-axis and y-axis statements to provide labels and values for the axis. Lastly, we use a format and label statement for the treatment group which will be used by the legend.

series x=month y=cd4/group=trt markers ; run; * Series plot connects the points, marker option needed to plot symbols at each visit; proc sgplot; series x=month y=cd4/group=trt markers ; run; If you want to connect the points then use the SERIES statement rather than the SCATTER statement. The MARKERS option tells SAS to “mark” the points with a symbol.

* Regression plot does scatter plot and adds regression line; proc sgplot; reg x=month y=cd4/group=trt ; run; If you want to display the best fitted regression line to each set of points use the REG statement. This will produce a scatter plot with a fitted line for each group.

* Step plot connects points with a step function; proc sgplot; step x=month y=cd4/group=trt ; run; If you want to connect the points with a step-function then use the STEP statement. We saw this in the example of generating a life-table curve.

SAS MAPS: Choropleth Map

Map Design There is an overall region (like country or state) There are sub-divisions of the region (like counties within states or states within country) Use color-coding to show data by sub-division (e.g. population, ethnicity, election results, length of growing season, stroke rates).

SAS Tools SAS has map datasets with latitude and longitude coordinates PROC GPROJECT projects the map dataset so points will plot properly on 2D image. PROC GMAP generates map with data associated with sub-regions of plot.

This is dataset with margin of victory (1-6) for each county. pattern1 c=CXAAAAFF ; pattern2 c=CX6F6FFF ; pattern3 c=CX3333FF ; pattern4 c=CXEEA6A6 ; pattern5 c=CXE26262 ; pattern6 c=CXCD2626 ; * Choro is a choropleth map; proc gmap map=mn_county data=county all; id county; choro wincat/ discrete ; format wincat wincat.; label wincat = 'Margin' ; run; Sets colors for 6 margin of victory levels. 1-3 are shades of blue, 4-6 are shades of red. This is dataset with margin of victory (1-6) for each county. Values 1-6 Needs to be on each dataset SAS supplied dataset that draws map

Has data to draw all county lines in US. State=27 is MN data mn_county; set maps.county; where state = 27; run; proc print data=mn_county (obs=10); Obs STATE SEGMENT COUNTY X Y 1 27 1 1 1.63672 0.81313 2 27 1 1 1.63669 0.81686 3 27 1 1 1.63668 0.82083 4 27 1 1 1.62412 0.82076 5 27 1 1 1.62422 0.81623 6 27 1 1 1.62411 0.81016 7 27 1 1 1.62409 0.80561 8 27 1 1 1.63068 0.80554 9 27 1 1 1.63066 0.80714 10 27 1 1 1.63705 0.80709

proc gproject data=mn_county out=mn_county; id county; run; Obs X Y STATE SEGMENT COUNTY 1 -.004946566 0.002584 27 1 1 2 -.004906222 0.006315 27 1 1 3 -.004879097 0.010286 27 1 1 4 0.003679749 0.010210 27 1 1 5 0.003628907 0.005679 27 1 1 6 0.003728457 -0.000393 27 1 1 7 0.003760163 -0.004944 27 1 1 8 -.000803074 -0.005021 27 1 1 9 -.000787884 -0.003421 27 1 1 10 -.005206215 -0.003457 27 1 1

Linking Data with Map Obs county county_name wincat 1 1 AITKIN 4 2 3 ANOKA 4 3 5 BECKER 5 4 7 BELTRAMI 2 5 9 BENTON 5 6 11 BIG STONE 4 7 13 BLUE EARTH 2 8 15 BROWN 6 9 17 CARLTON 3 10 19 CARVER 6 11 21 CASS 5 12 23 CHIPPEWA 1 13 25 CHISAGO 5 14 27 CLAY 2 15 29 CLEARWATER 5 16 31 COOK 3 17 33 COTTONWOOD 6 18 35 CROW WING 5 19 37 DAKOTA 1 20 39 DODGE 5 Coded 1-6 dependent on level of difference between Romney and Obama

This is dataset with margin of victory (1-6) for each county. pattern1 c=CXAAAAFF ; pattern2 c=CX6F6FFF ; pattern3 c=CX3333FF ; pattern4 c=CXEEA6A6 ; pattern5 c=CXE26262 ; pattern6 c=CXCD2626 ; proc gmap map=mn_county data=county all; id county; choro wincat/ discrete ; format wincat wincat.; label wincat = 'Margin' ; run; Sets colors for 6 margin of victory levels. 1-3 are shades of blue, 4-6 are shades of red. This is dataset with margin of victory (1-6) for each county. Needs to be on each dataset

Obama versus Romney: 2012

Trump versus Clinton: 2016 19

SAS Program to create map libname e '~/Election/2012/'; data election; set e.president_county_2012; where candidate_id in('0301','0401'); county = county_id*2 - 1; drop state pctvote; run; proc sort; by county_id candidate_id; data county; set election; by county_id; retain RomneyVotes ObamaVotes ; if first.county_id then do; RomneyVotes = . ; ObamaVotes = . ; end; if candidate_id = '0301' then RomneyVotes = votes_candidate; if candidate_id = '0401' then ObamaVotes = votes_candidate; if last.county_id then output; drop votes_candidate candidate_id; set county; RomneyPct = 100*RomneyVotes / totvotes; ObamaPct = 100*ObamaVotes / totvotes; votedifpct = RomneyPct - ObamaPct ; if votedifpct < -15 then wincat = 3; else if votedifpct < - 5 then wincat = 2; else if votedifpct < 0 then wincat = 1; else if votedifpct < 5 then wincat = 4; else if votedifpct < 15 then wincat = 5; else if votedifpct >=15 then wincat = 6; SAS Program to create map

proc format; value wincat 1 = 'Obama 0-5' 2='Obama 5-15' 3='Obama 15+' 4 = 'Romney 0-5' 5='Romney 5-15' 6='Romney 15+'; proc print; format wincat wincat.; run; goptions reset=all border device=png gsfname=gsf; pattern1 c=CXAAAAFF ; pattern2 c=CX6F6FFF ; pattern3 c=CX3333FF ; pattern4 c=CXEEA6A6 ; pattern6 c=CXCD2626 ; pattern5 c=CXE26262 ; data mn_county; set maps.county; where state = 27; proc gproject data=mn_county out=mn_county; id county; filename gsf “election2012.png"; proc gmap map=mn_county data=county all ; choro wincat/ discrete ; format wincat wincat.; label wincat = 'Margin' ; quit;

Where to get help for SAS? Google Help within PC SAS SAS Documentation on web: http://support.sas.com/documentation/onlinedoc/bookshelf/93/ Take a class from SAS Take a class from OIT at U of M http://it.umn.edu/list-courses (free online classes) UCLA website www.ats.ucla.edu/stat/sas I hoped you have enjoyed the class and use some of what you learned in your research or other areas. Before I go let me give you some suggestions of where to find SAS help. First of all, there are SAS manuals. These can be costly and there are many of them. You may want to invest in just some of them, perhaps like SAS procedures. More recently SAS has made available online and in the help within PC SAS essentially every manual. The online help is entirely free. The web site for the current version of SAS is listed here. This is where I go for SAS help the most. Lastly, UCLA has a web site that has several free tutorials you can try. SAS institute and some independent groups give classes periodically on several topics. One of the regional headquarters is in downtown Minneapolis. You can find the schedule of classes on the SAS support web site. Lastly, please provide feedback on what you thought of this class and how it may be improved. Have a great rest of the Summer.