In this article you’ll learn how to create country-level maps in SAS Studio using BASE SAS code. You’ll learn how to draw country maps highlighting their states, regions or counties.
There is a common structure to follow to create any country-level maps without much hustle.
The coordinates and all the required information is already available in the SAS Maps libraries. You can refer to any library, “maps”, “mapssas”, or “mapsgfk”.
I have used the “maps” library to create country maps to demonstrate in this article. You can also follow the same.
How to Create Country Maps in SAS?
The maps in SAS can be created using PROC GMAP procedure. You can easily create any map including a country map, city map, state map, and so on.
In this article I’ll explain it to you how to create maps of six countries including:
- USA
- India
- UK
- Canada
- Germany
You’ll be able to create maps for other countries as well by following the same code structure and with minor changes.
The PROC GMAP Procedure
The GMAP procedure produces two-dimensional (choropleth) or three-dimensional (block, prism, and surface) maps that show variations of a variable value with respect to an area. Map data sets and response data sets are used in the GMAP procedure.
/* syntax proc gmap procedure */
PROC GMAP MAP=map-data-set
DATA=response-data-set
<ALL>
<ANNOTATE=Annotate-data-set>
<DENSITY=0 ...6 | LOW | MEDIUM | HIGH>
<GOUT=<libref.>output-catalog>
<IMAGEMAP=output-data-set>
<LATLON>
<RESOLUTION=1 ...10 | AUTO | NONE>
<STRETCH>
<UNIFORM>;
ID id-variable(s);
AREA response-variable </ options>;
BLOCK response-variable(s) </ options>;
CHORO response-variable(s) </ options>;
PRISM response-variable(s) </ options>;
SURFACE response-variable(s) </ options>;
RUN;
QUIT;
There are 4 Types of Maps you can create in SAS using GMAP procedure as follows:
- Two-dimensional (choropleth)
- BLOCK Maps
- PRISM Maps
- SURFACE Maps
To create a simple country map 2D (choropleth) map is more than enough. So we’ll use proc gmap with Two-dimensional (choropleth) to create maps in SAS.
If you want to learn in indepth different types of the maps in SAS with examples then check out this article.
If you look at proc gmap syntax, the most important things you need is map-data-set and response-data-set. As stated earlier, you’ll find these both the data sets in the SAS library called “MAPS”.
In the MAPS library you’ll find a bunch of country specific data sets with all the information needed to draw the map using the proc gmap procedure.
1. Create USA Map in SAS
To create the USA map we will use the following input data sets from “MAPS” SAS library to be used in the proc gmap procedure.
- map-data-set: maps.us
- response-data-set: maps.us2
Let’s print the first 10 observations to get to know better about these data sets.
/* print input data sets */
proc print data=maps.us(obs=10);
title 'print maps.us data set'; run;
proc print data=maps.us2(obs=10);
title 'print maps.us2 data set'; run;
We’ll create the USA map by highlighting its states. The mapping data set and response data set can be linked together using a common attribute state to fetch statename attribute from response data set.
/* create USA country Map */
title1 'EXAMPLE - MAPS.USA MAP DATA SET';
title2 'UNITED STATES OF AMERICA';
/* draw the map */
proc gmap map=maps.us data=maps.us2(keep=state statename) ;
id state;
choro statename ;
run;
quit;
Map with Annotation
In case you want to create a map with annotation, you need to use the following two SAS macros %ANNOMAC and %MAPLABEL.
You need to use the <ANNOTATE=Annotate-data-set> option to add annotation in the GMAP procedure. You don’t manually create <Annotate-data-set> data set, instead you use inbuilt sas macros in the beginning of your code.
- The %ANNOMAC macro which tells SAS to have the annotate macros ready to be used.
- The next step is calling the %MAPLABEL macro which will create the annotate dataset to be called in PROC GMAP in the annotate statement.
Here is the sample example demonstrating how to pass the values for %maplabel macro to create Annotate-data-set for gmap procedure.
- Map-dataset: maps.us
- Attr-dataset: maps.us2
- Output-dataset: annoDS
- Label-var: statename
- Id-list: state
- font=’Albany AMT’
- Color= black
- Size= 1.8
/* The USA Map with Annotation */
%ANNOMAC;
%MAPLABEL(maps.us, maps.us2, annoDS, statename, state, font='Albany AMT',
color=black, size=1.8);
title1 ' The United States of America ';
proc gmap map=maps.us data=maps.us2(keep=state statename) ;
id state;
choro statename / annotate=annoDS discrete nolegend;
run;
quit;
2. Create INDIA Map in SAS
To create the INDIA map we will use the following input data sets from “MAPS” SAS library to be used in the proc gmap procedure.
- map-data-set: maps.india
- response-data-set: maps.india2
Let’s print the first 10 observations to get to know better about these data sets.
/* print input data sets */
proc print data=maps.india(obs=10);
title 'print maps.india data set'; run;
proc print data=maps.india2(obs=10);
title 'print maps.india2 data set'; run;
We’ll create the INDIA map by highlighting its states. The mapping data set and response data set can be linked together using a common attribute id to fetch idname attribute for the state names from response data set.
/* create INDIA country Map */
title1 'EXAMPLE - MAPS.INDIA MAP DATA SET';
title2 ' INDIA / BHARAT';
/* draw the map */
proc gmap map=maps.india data=maps.india2(keep=ID IDNAME) ;
id id;
choro idname;
run;
quit;
3. Create UK Map in SAS
To create the UK map we will use the following input data sets from “MAPS” SAS library to be used in the proc gmap procedure.
- map-data-set: maps.uk
- response-data-set: maps.uk2
Let’s print the first 10 observations to get to know better about these data sets.
/* print input data sets */
proc print data=maps.uk(obs=10);
title 'print maps.uk data set'; run;
proc print data=maps.uk2(obs=10);
title 'print maps.uk2 data set'; run;
We’ll create the UK map by highlighting its different regions. The mapping data set and response data set can be linked together using a common attribute id to fetch region attribute from response data set.
/* create UK Map */
title1 'EXAMPLE - MAPS.UK MAP DATA SET';
title2 ' United Kingdom ';
/* draw the map */
proc gmap map=maps.uk data=maps.uk2(keep=id idname region) ;
id id;
choro region;
run;
quit;
4. Create CANADA Map in SAS
To create the CANADA map we will use the following input data sets from “MAPS” SAS library to be used in the proc gmap procedure.
- map-data-set: maps.canada
- response-data-set: maps.cancens
Let’s print the first 10 observations to get to know better about these data sets.
/* print input data sets */
proc print data=maps.canada(obs=10);
title 'print maps.canada data set'; run;
proc print data=maps.cancens(obs=10);
title 'print maps.cancens data set'; run;
We’ll create the CANADA map by highlighting its different regions(PROVINCE). The mapping data set and response data set can be linked together using a common attribute province to fetch provname attribute from the response data set.
/* create CANADA country Map */
title1 'EXAMPLE - MAPS.CANADA MAP DATA SET';
title2 ' CANADA ';
/* draw the map */
proc gmap map=maps.canada data=maps.cancens(keep=province provname name) ;
id province;
choro provname;
run;
quit;
5. Create GERMANY Map in SAS
To create the GERMANY map we will use the following input data sets from “MAPS” SAS library to be used in the proc gmap procedure.
- map-data-set: maps.germany
- response-data-set: maps.germany2
Let’s print the first 10 observations to get to know better about these data sets.
/* print input data sets */
proc print data=maps.germany(obs=10);
title 'print maps.germany data set'; run;
proc print data=maps.germany2(drop=idname obs=10);
title 'print maps.germany2 data set'; run;
We’ll create the GERMANY map by highlighting its different states. The mapping data set and response data set can be linked together using a common attribute id to fetch state1 attribute for state names from the response data set.
/* create GERMANY country Map */
title1 'EXAMPLE - MAPS.GERMANY MAP DATA SET';
title2 ' GERMANY ';
/* draw the map */
proc gmap map=maps.germany data=maps.germany2(keep=id state1 ) ;
id id;
choro state1;
run;
quit;
6. Create NORWAY Map in SAS
To create the NORWAY map we will use the following input data sets from “MAPS” SAS library to be used in the proc gmap procedure.
- map-data-set: maps.norway
- response-data-set: maps.norway2
Let’s print the first 10 observations to get to know better about these data sets.
/* print input data sets */
proc print data=maps.norway(obs=10);
title 'print maps.norway data set'; run;
proc print data=maps.norway2(obs=10);
title 'print maps.norway2 data set'; run;
We’ll create the NORWAY map by highlighting its different regions(County). The mapping data set and response data set can be linked together using a common attribute id to fetch idname attribute for county names from the response data set.
/* create NORWAY country Map */
title1 'EXAMPLE - MAPS.NORWAY MAP DATA SET';
title2 ' The Kingdom of NORWAY ';
/* draw the map */
proc gmap map=maps.norway data=maps.norway2(keep=id idname ) ;
id id;
choro idname;
run;
quit;
FAQ
To create country-level maps in SAS, you can use PROC GMAP procedure. Specify the country-level map file and your data, and use appropriate options and statements to customize the map.
You can also set colors, legends, and labels to enhance the map’s readability and visual appeal.
SAS provides map files for individual countries in the SAS Maps library. These files include detailed geographic information for countries worldwide.
You can access these map files directly from SAS procedures and use them to create country-level maps. Additionally, you can create custom map files if you need specific geographic boundaries or data points.
Yes, you can create thematic maps for specific countries in SAS. Use the CHORO statement in PROC GMAP to create thematic maps based on variables specific to each country.
This allows you to visualize data patterns and variations within individual countries, making it a powerful tool for in-depth country-level analysis. You can customize colors, data ranges, and legends to effectively convey the information on your thematic maps.