The process begins with the preparation of mapping data from the 'maps' library. The script merges the polygons of Germany's regions ('maps.germany') with information about their belonging to the 16 states ('maps.germany2'). Next, the GREMOVE procedure is used to dissolve the internal borders of the regions, retaining only the contours of the states. An annotation dataset is then calculated to position the names of the states in the center of their territory on the map. Finally, the GMAP procedure generates the final map in an HTML file, representing each state with a distinct color and displaying its name.
Data Analysis
Type : MIXTE
The script uses the `maps.germany` and `maps.germany2` tables, which are system tables provided with the SAS/GRAPH module. It then creates intermediate working tables (`germany`, `anno_names`) to aggregate and prepare the data for visualization.
1 Code Block
DATA STEP Data
Explanation : Creates a 'germany' working table from the 'maps.germany' system table. An 'original_order' variable is added to preserve the initial order of observations, which will be useful for subsequent sorting.
Copied!
data germany; set maps.germany;
original_order=_n_;
run;
1
2
DATA germany;
3
SET maps.germany;
4
original_order=_n_;
5
RUN;
6
2 Code Block
PROC SQL Data
Explanation : Joins the 'germany' working table with the 'maps.germany2' table to associate each region (id) with its respective state (state2). The result replaces the 'germany' table and is sorted by state.
Copied!
proc sql;
create table germany as
select unique germany.*, germany2.state2
from germany left join maps.germany2
on germany.id=germany2.id
order by state2, original_order;
quit; run;
1
PROC SQL;
2
create TABLE germany as
3
select unique germany.*, germany2.state2
4
from germany left join maps.germany2
5
on germany.id=germany2.id
6
order BY state2, original_order;
7
QUIT; RUN;
3 Code Block
PROC GREMOVE Data
Explanation : Uses the GREMOVE procedure to dissolve the polygon boundaries within each group defined by 'state2'. This transforms the map of regions into a map of the 16 states.
Copied!
proc gremove data=germany out=germany;
by state2;
id id;
run;
1
PROC GREMOVEDATA=germany out=germany;
2
BY state2;
3
id id;
4
RUN;
4 Code Block
MACRO / DATA STEP Data
Explanation : The %annomac and %centroid macros calculate the geographical center of each state to place a label there. A subsequent DATA STEP modifies this annotation dataset to manually adjust the position of some state names to improve the readability of the final map.
Copied!
%annomac;
%centroid(germany, anno_names, state2);
data anno_names; set anno_names;
length function $8;
hsys='3'; when='a'; size=2;
xsys='2'; ysys='2'; function='move'; output;
/* Give a few of the labels an x/y offset, to move to a better location (x/y values in relative %) */
x=0; y=0;
text=trim(left(state2));
if text='Brandenburg' then y=-1.5;
if text='Niedersachsen' then y=y+1.5;
if text='Sachsen' then x=-1;
xsys='b'; ysys='b'; function='move'; output;
function='cntl2txt'; output;
function='label'; output;
run;
1
%annomac;
2
%centroid(germany, anno_names, state2);
3
4
DATA anno_names; SET anno_names;
5
LENGTH function $8;
6
hsys='3'; when='a'; size=2;
7
xsys='2'; ysys='2'; function='move'; OUTPUT;
8
/* Give a few of the labels an x/y offset, to move to a better location (x/y values in relative %) */
9
x=0; y=0;
10
text=trim(left(state2));
11
IF text='Brandenburg'THEN y=-1.5;
12
IF text='Niedersachsen'THEN y=y+1.5;
13
IF text='Sachsen'THEN x=-1;
14
xsys='b'; ysys='b'; function='move'; OUTPUT;
15
function='cntl2txt'; OUTPUT;
16
function='label'; OUTPUT;
17
RUN;
5 Code Block
PROC GMAP
Explanation : Configures the graphical environment (GOPTIONS) and the output delivery system (ODS) to generate an HTML file. The GMAP procedure then draws the choropleth map based on the 'germany' table for polygons and colors, and on the 'anno_names' table to superimpose text labels.
Copied!
GOPTIONS DEVICE=png;
goptions cback=white border;
goptions gunit=pct ftitle='albany amt/bold' ftext='albany amt' htitle=4 htext=2.75;
ODS LISTING CLOSE;
ODS HTML path=odsout body="&name..htm" style=sasweb;
legend1 position=(right middle) label=none across=1 shape=bar(.15in,.15in);
title1 ls=1.5 "16 States of Germany";
proc gmap map=germany data=germany anno=anno_names;
id state2;
choro state2 / discrete coutline=gray legend=legend1
des="" name="&name";
run;
quit;
ODS HTML CLOSE;
ODS LISTING;
choro state2 / discrete coutline=gray legend=legend1
15
des="" name="&name";
16
RUN;
17
18
QUIT;
19
ODS HTML CLOSE;
20
ODS LISTING;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
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. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.