Lesson 13 Another MACRO Example MAP Plotting. Macro Example Goal of Macro named Summary: For a given dataset give summary statistics using PROC CONTENTS,

Slides:



Advertisements
Similar presentations
Statistics in Science  Introducing SAS ® software Acknowlegements to David Williams Caroline Brophy.
Advertisements

Sexually Transmitted Disease (STD) Surveillance Report, 2002 Minnesota Department of Health STD Surveillance System Minnesota Department of Health STD.
Today: Run SAS programs on Saturn (UNIX tutorial) Runs SAS programs on the PC.
1 SAS Formats and SAS Macro Language HRP223 – 2011 November 9 th, 2011 Copyright © Leland Stanford Junior University. All rights reserved. Warning:
National Center on Educational Outcomes (NCEO) Introduction to the NCEO Data Viewer National Center on Educational Outcomes Communities of Practice Teleconference.
Basic And Advanced SAS Programming
PROC_CODEBOOK: An Automated, General Purpose Codebook Generator
Introduction to SAS Lecture 2 Brian Healy.
Data Cleaning 101 Ron Cody, Ed.D Robert Wood Johnson Medical School Piscataway, NJ.
FORMAT FESTIVAL AN INTRODUCTION TO SAS® FORMATS AND INFORMATS By David Maddox.
ArcGIS Overview Lecture 1: Software Layer characteristics Thematic maps.
SAS PROC REPORT PROC TABULATE
SAS Workshop Lecture 1 Lecturer: Annie N. Simpson, MSc.
Introduction to SAS Essentials Mastering SAS for Data Analytics Alan Elliott and Wayne Woodward SAS ESSENTIALS -- Elliott & Woodward1.
Introduction to SAS BIO 226 – Spring Outline Windows and common rules Getting the data –The PRINT and CONTENT Procedures Manipulating the data.
Creating Maps with SAS/GRAPH - Drill Downs, Pop-Ups, and Animation.
Using SAS® and Google Earth ™ to Access and Display Air Pollution Data RTSUG Meeting September 10, 2008 Joshua Drukenbrod U.S. EPA Office of Air Quality.
Introduction to PROC GMap Presentation by Andrea Boan BMTRY 789.
SAS 介绍和举例 Presented by 经济实验教学中心 商务数据挖掘中心. Raw Data Read in Data Process Data (Create new variables) Output Data (Create SAS Dataset) Analyze Data Using.
SAS Efficiency Techniques and Methods By Kelley Weston Sr. Statistical Programmer Quintiles.
Public Employees Retirement Association of Minnesota GASB 68 Audit Issues for Cost-Sharing Plans Presented by Jim Riebe, PERA Principal Accounting Officer.
SAS Mapping functionality to measure and present the Veracity of Location Data.
01/20151 EPI 5344: Survival Analysis in Epidemiology SAS code and output February 24, 2015 Dr. N. Birkett, School of Epidemiology, Public Health & Preventive.
© 2004 by David T. Olson Sample - Not for Public Use1 A Sample Presentation of The State of the Church in Minnesota and the Minneapolis / St. Paul Metro.
SAS ODS (Output Delivery System) Donald Miller 812 Oswald Tower ;
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.
Introduction to SAS Macros Center for Statistical Consulting Short Course April 15, 2004.
© OCS Biometric Support 1 APPEND, EXECUTE and MACRO Jim Groeneveld, OCS Biometric Support, ‘s Hertogenbosch, Netherlands. PhUSE 2010 – CC05 PhUSE 2010.
Chapter 4 concerns various SAS procedures (PROCs). Every PROC operates on: –the most recently created dataset –all the observations –all the appropriate.
Primary* Refugee Arrivals to MN by Region of World Refugee Health Program, Minnesota Department of Health *First resettled in Minnesota.
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.
SAS Basics. Windows Program Editor Write/edit all your statement here.
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.
Sexually Transmitted Disease (STD) Surveillance Report, 2011 Minnesota Department of Health STD Surveillance System Minnesota Department of Health STD.
FORMAT statements can be used to change the look of your output –if FORMAT is in the DATA step, then the formats are permanent and stored with the dataset.
Customize SAS Output Using ODS Joan Dong. The Output Delivery System (ODS) gives you greater flexibility in generating, storing, and reproducing SAS procedure.
Creating Geographic Rating Area Maps: How to Combine Counties, Split Counties, & use Zip Code Boundaries Rick Andrews Office of the Actuary Centers for.
Chapter 8: Using Basic Statistical Procedures “33⅓% of the mice used in the experiment were cured by the test drug; 33⅓% of the test population were unaffected.
How to Generate Online Reports using WBTi Toolkit.
© 2004 by David T. Olson Sample - Not for Public Use1 The State of the Church in Minnesota Dave Olson
Public Employees Retirement Association of Minnesota What GASB 68 Information Will PERA Provide to Employers? Presented by Jim Riebe, PERA Principal Accounting.
Public Employees Retirement Association of Minnesota Calculating Employer’s Proportionate Share of Collective Pension Amounts Presenter: Jim Riebe Principal.
SAS Programming Training Instructor:Greg Grandits TA: Textbooks:The Little SAS Book, 5th Edition Applied Statistics and the SAS Programming Language, 5.
1 Checking Data with the PRINT and FREQ Procedures.
HRP Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected by copyright law and.
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
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 14 & 19 By Tasha Chapman, Oregon Health Authority.
Better Metadata Through SAS® II: %SYSFUNC, PROC DATASETS, and Dictionary Tables.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 16 & 17 By Tasha Chapman, Oregon Health Authority.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 5 & 6 By Ravi Mandal.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 3 & 4 By Tasha Chapman, Oregon Health Authority.
Applied Business Forecasting and Regression Analysis
Lesson 13 More SGPLOT examples MAP Plotting Questions.
2016 Minnesota Student survey adverse childhood experiences data
Lesson 11 - Topics Statistical procedures: PROC LOGIST, REG
3 Macro Parameters.
Chapters 5 and 7 supplement
Quick Data Summaries in SAS
Complete Case Macro.
Primary* Refugee Arrivals to MN by Region of World
Primary* Refugee Arrivals to MN by Region of World
Primary* Refugee Arrivals to MN by Region of World
Primary* Refugee Arrivals to MN by Region of World
Primary* Refugee Arrivals to MN by Region of World
Primary* Refugee Arrivals to MN by Region of World
Ungraded quiz Unit 7.
Presentation transcript:

Lesson 13 Another MACRO Example MAP Plotting

Macro Example Goal of Macro named Summary: For a given dataset give summary statistics using PROC CONTENTS, MEANS and FREQ and (optionally) display the data using PROC PRINT. Instead of having to write the code each time, write a macro.

%macro summary (dataset=, mvar=_numeric_, fvar = _character_, print=N, pvar=_all_); Parameters to Macro = defaults Name of macro Dataset:Name of dataset used Mvar:List of variables to run for PROC MEANS (default is all numeric var) Fvar:List of variables to run for PROC FREQ (default is all character var) Print:If set to Y then run PROC PRINT (default is N) Pvar:List of variables to run for PROC PRINT Remember: SAS Macros generate SAS code when you call it

%macro summary (dataset=, mvar=_numeric_, fvar = _character_, print=N, pvar=_all_); proc contents data=&dataset varnum; run; proc means data=&dataset; var &mvar; run; proc freq data=&dataset; tables &fvar; run; %if &print = Y %then %do; proc print data=&dataset; var &pvar; %end; %mend summary; Parameters to Macro Name of macro This will generate the proc print code only if the macro variable print equals Y.

CALL TO MACRO: libname here '~/PH6420/data/'; data state; set here.pop; run; option mprint; %summary (dataset=state); Code Generated: MPRINT(SUMMARY): proc contents data=state varnum; MPRINT(SUMMARY): run; MPRINT(SUMMARY): proc means data=state; MPRINT(SUMMARY): var _numeric_; MPRINT(SUMMARY): run; MPRINT(SUMMARY): proc freq data=state; MPRINT(SUMMARY): tables _character_; MPRINT(SUMMARY): run; * This is the macro; proc contents data=&dataset varnum; run; proc means data=&dataset; var &mvar; run; proc freq data=&dataset; tables &fvar; run; %if &print = Y %then %do; proc print data=&dataset; var &pvar; %end;

CALL TO MACRO: libname here '~/PH6420/data/'; data state; set here.pop; run; option mprint; %summary (dataset=state, print=Y); Code Generated: MPRINT(SUMMARY): proc contents data=state varnum; MPRINT(SUMMARY): run; MPRINT(SUMMARY): proc means data=state; MPRINT(SUMMARY): var _numeric_; MPRINT(SUMMARY): run; MPRINT(SUMMARY): proc freq data=state; MPRINT(SUMMARY): tables _character_; MPRINT(SUMMARY): run; MPRINT(SUMMARY): proc print data=state; MPRINT(SUMMARY): var _all_; MPRINT(SUMMARY): run; * This is the macro; proc contents data=&dataset varnum; run; proc means data=&dataset; var &mvar; run; proc freq data=&dataset; tables &fvar; run; %if &print = Y %then %do; proc print data=&dataset; var &pvar; %end;

CALL TO MACRO: libname here '~/PH6420/data/'; data state; set here.pop; run; option mprint; %summary (dataset=state,fvar=state statename); Code Generated: MPRINT(SUMMARY): proc contents data=state varnum; MPRINT(SUMMARY): run; MPRINT(SUMMARY): proc means data=state; MPRINT(SUMMARY): var _numeric_; MPRINT(SUMMARY): run; MPRINT(SUMMARY): proc freq data=state; MPRINT(SUMMARY): tables state statename; MPRINT(SUMMARY): run; * This is the macro; proc contents data=&dataset varnum; run; proc means data=&dataset; var &mvar; run; proc freq data=&dataset; tables &fvar; run; %if &print = Y %then %do; proc print data=&dataset; var &pvar; %end;

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).

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 (optional) data associated with sub-regions of plot.

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. Needs to be on each dataset SAS supplied dataset that draws map

data mn_county; set maps.county; where state = 27; run; proc print data=mn_county (obs=10); run; Obs STATE SEGMENT COUNTY X Y Has data to draw all county lines in US. State=27 is MN

proc gproject data=mn_county out=mn_county; id county; run; Obs X Y STATE SEGMENT COUNTY

proc gmap map=mn_county data=mn_county; id county; choro county/nolegend discrete; run;

proc gmap map=mn_county data=mn_county; id county; choro county/nolegend levels=1; run;

Linking Data with County Obs county county_name wincat 1 1 AITKIN ANOKA BECKER BELTRAMI BENTON BIG STONE BLUE EARTH BROWN CARLTON CARVER CASS CHIPPEWA CHISAGO CLAY CLEARWATER COOK COTTONWOOD CROW WING DAKOTA DODGE 5 Coded 1-6 dependent on level of difference between Romney and Obama

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

SAS MAPS

* Draw map of US; data states; set maps.states; if state in(2,72,15) then delete; run; proc gproject data=states out=states; id state; run; proc gmap map=states data=states; id state; choro state/ discrete nolegend ; run;

Where to get help for SAS? Google Help within PC SAS SAS Documentation on web: Take a class from SAS Take a class from OIT at U of M (free online classes) UCLA website