Decorate your Map with SAS annotate facilities Group Presentatio… · choro segment ; run; quit;...

28
Decorate your Map with SAS annotate facilities

Transcript of Decorate your Map with SAS annotate facilities Group Presentatio… · choro segment ; run; quit;...

Decorate your Map with SAS annotate facilities

If a picture is worth a thousand words, then a map can

be worth a thousand pictures.

- Darrell Massengill and Jeff Phillips

Why Graphs and Maps?

Getting the Shape files• You will need the following 4 files:

proc mapimportdatafile=‘/.../yourpath/rm_all_latlong_II.shp'out=RM_all_region;

run;

Use SAS shipped Datasets

• SAS provide Canada map with x-y coodinates:

proc gproject data=maps.canada3 out=canada3 dupokproject=hammer;

id segment province;run;

www.geosask.ca

Creating base map• Proc GMAP is used to create a base map:

Map data source and response data source

proc gmap data=canada3 map=canada3 all;id province cdcode;choro segment ;

run;quit;

SASK Map

# Variable Type Len Label

5 CDCODE Char 2 Census Division

3 DENSITY Num 4 Density for Lower Resolution Maps

4 PROVINCE Char 2 Province Abbreviation

6 SEGMENT Num 4 Census District Segment Number

1 X Num 5 Projected Longitude: Hammer

2 Y Num 5 Projected Latitude: Hammer

SASK Data

# Variable Type Len Label

2 CDCODE Char 2 Census Division

1 PROVINCE Char 2 Province Abbreviation

3 SEGMENT Num 4 Census District Segment Number

5 Ab Num 8 Aboriginal Population

4 Non_ab Num 8 Other population

6 total Num 8 Total Population

Map Data

Response

Data

Mapping our Data

Pattern1 C=LightGreen;Pattern2 C=Cyan;Pattern3 C=Yellow;Pattern4 C=Orange;Pattern5 C=Red;proc sort data=sask;by cdcode;run;

proc gmap data=sask_data map=sask_maps all;

id province cdcode;choro pop/discrete ;

run;quit;

Bar Chart Over Map

proc gmap data=sask_data map=sask_maps all;

id province cdcode;

block ab /

blocksize=2

shape=block

woutline=1

cdefault=cxccffcc

cempty=cxccffcc

coutline=black

nolegend

;run;quit;

Annotate Facility

• Annotate dataset is the pen of your SAS program.

A. What to do;

B. How to do it;

C. Where to do it.

A closer look…

Create Annotate dataset Manually

data line_anno;length function color $8 position $1;retain xsys ysys '2' hsys '3' when 'a' position '5';

function='move'; x=-120 ; y=1790; output;

function='draw'; line=3; size=0.5;color='black';x=110;y=1790; output;

function='label';size=3;color='black'; style='Arial Black';x=95; y=1800; text='Northern'; output;run;

proc gmap data=sask_data map=sask_maps all;id province cdcode;choro pop/discrete annotate=line_anno;

run;quit;

Create Annotate Dataset using Macro

%ANNOMAC;%MAPLABEL(sask_maps,sask_data,sask_anno,cdcode,cdcode,font=Arial Black, color=grey, size=2, hsys=3)

proc gmap data=sask_data map=sask_maps all;id province cdcode;choro pop/discrete annotate=sask_anno;

run;quit;

data sask_anno;set sask_anno;

if text=“17" then position="2";

if text=“12" then position='8';

Adjust Position

Pie Chart over map

%annomac;%centroid( sask_maps, sask_centers, province cdcode);

Sask_centers dataset

data anno_pies; set anno_pies; area=(total/&max_val)*&max_area;size=.3 + sqrt(area/3.14);run;

data anno_pies; set anno_pies; length function color $8 html $500;

non_pct=pop/total;ab_pct=ab/total;

xsys='2'; ysys='2'; hsys='3'; when='A'; html='';function='PIE'; line=0; style='psolid';

/* Non Aboriginal pie slice */rotate=non_pct*360; color="cxff0000"; output;

/* Aboriginal's pie slice */rotate=ab_pct*360;color="cx0084a8"; output;run;

More Labels

html='title'=||quote(trim(left(cdcode))||'0D'x||

'Aboriginal:'||put(fn_pct,percent6.0)||'0D'x||'non-Aboriginal: '||put(non_pct,percent6.0))||;

Other Graphs

2-bar Charts• http://robslink.com/SAS/democd58/doublebar_map.htm

Other Amazing Maps

• This program downloads map tile images from OpenStreetMaps (or other similar web-based map services), and 'knits' those image tiles together into the background of a SAS/Graph gplot, and plots lat/long data onto those maps (in the correct location).

http://robslink.com/SAS/democd41/china_ports.htm

Interact with Google Maps

http://robslink.com/SAS/democd71/tornado_animation.htmAnimated Maps

Ultimate Goal

Why use SAS instead of…Excel?

1. SAS map is all data driven, once the initial code is set up, there is little manual work;

2. It is easy to calculate statistics in SAS;

3. Output can be easily stored in PDF format;

4. SAS is able to handle large volume of data.

References

• Jeffery D. Gilbert Customizing SAS Graphs Using the Annotate Facility and Global Statements. SUGI 24

• Robs’ Link: http://robslink.com/