Published on :

Map of the 16 German Länders

This code is also available in: Deutsch Español Français
Awaiting validation
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!
1 
2DATA germany;
3SET maps.germany;
4original_order=_n_;
5RUN;
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!
1PROC SQL;
2create TABLE germany as
3select unique germany.*, germany2.state2
4from germany left join maps.germany2
5on germany.id=germany2.id
6order BY state2, original_order;
7QUIT; 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!
1PROC GREMOVE DATA=germany out=germany;
2BY state2;
3id id;
4RUN;
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!
1%annomac;
2%centroid(germany, anno_names, state2);
3 
4DATA anno_names; SET anno_names;
5LENGTH function $8;
6hsys='3'; when='a'; size=2;
7xsys='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 %) */
9x=0; y=0;
10text=trim(left(state2));
11IF text='Brandenburg' THEN y=-1.5;
12IF text='Niedersachsen' THEN y=y+1.5;
13IF text='Sachsen' THEN x=-1;
14xsys='b'; ysys='b'; function='move'; OUTPUT;
15function='cntl2txt'; OUTPUT;
16function='label'; OUTPUT;
17RUN;
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!
1GOPTIONS DEVICE=png;
2goptions cback=white border;
3goptions gunit=pct ftitle='albany amt/bold' ftext='albany amt' htitle=4 htext=2.75;
4
5ODS LISTING CLOSE;
6ODS HTML path=odsout body="&name..htm" style=sasweb;
7 
8legend1 position=(right middle) label=none across=1 shape=bar(.15in,.15in);
9 
10title1 ls=1.5 "16 States of Germany";
11 
12PROC GMAP map=germany DATA=germany anno=anno_names;
13id state2;
14choro state2 / discrete coutline=gray legend=legend1
15 des="" name="&name";
16RUN;
17 
18QUIT;
19ODS HTML CLOSE;
20ODS 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.