Amadeus cookies policy - you'll see this message only once.

Amadeus use cookies on this website. They help us to know a little bit about you and how you use our website, which improves the browsing experience and marketing - both for you and for others. They are stored locally on your computer or mobile device. To accept cookies, continue browsing as normal. Or, go to the privacy policy for more information.

Maps in ODS Graphics – Proc SGMAP

The number of graphics tasks that can only be done using traditional SAS graphics (the SAS/GRAPH product) continues to decrease. With the arrival of SAS® 9.4 TS1 M5, ODS Graphics (which is part of Base SAS) can now handle maps for the first time. Unless you read the “What’s new?” notes carefully, it’s possible you could have missed this. The new Proc SGMAP is not documented with the other SG procedures under “ODS Graphics”. It will only be found in the next section of the documentation, “SAS/GRAPH and Base SAS 9.4: Mapping Reference”.

Two SAS procedures, MAPIMPORT and GEOCODE, have been moved from SAS/GRAPH into Base SAS. These procedures can therefore be used freely in conjunction with Proc SGMAP.

Several types of map can be plotted using Proc SGMAP:

  • SAS-supplied maps from libraries MAPSSAS and MAPSGFK can be plotted using the CHOROMAP statement – though this is designated “pre-production” in release M5.
  • ESRI maps can be plotted using the ESRIMAP statement.
  • OPENSTREETMAP maps can plotted using the OPENSTREETMAP statement, which can be abbreviated to OSM.

Examples of all three are given below.

Any of these maps can be embellished using TEXT, SCATTER and BUBBLE statements. Some other standard ODS Graphics statements such as STYLEATTRS are not available.

This program demonstrates the CHOROMAP statement being used to plot a map of Great Britain. MAPSSAS.UK contains the outlines of the counties, and MAPSSAS.UK2 gives identifying information, including the county names. The WHERE clause in the first query eliminates Northern Ireland and the Orkneys and Shetlands, to keep the map relatively clean. The second query yields a table containing the county names and the co-ordinates of the centroids of the counties, where the names will be plotted.

Maps in ODS Graphics Proc SGMAP Image 1 

Three data sets are here input to Proc SGMAP, two of them being physically identical in this case. MAPDATA contains the outlines which will be plotted by CHOROMAP. MAPRESPDATA contains the response data, which will determine the colours CHOROMAP uses when filling areas. PLOTDATA supplies the TEXT statement with the county names. The options to the CHOROMAP statement specify the ID variables for the MAPDATA and MAPRESPDATA data sets respectively. “ID” is in fact the default for both of these options, but the documentation warns that SGMAP may run slowly if these options are not specified explicitly. IDNAME here is the response variable which will determine the colours. In this case it is a character variable containing the county names, which are all unique, so the resulting map is correspondingly colourful. 

Maps in ODS Graphics Proc SGMAP Image 2

The OPENSTREETMAP statement specifies that an OpenStreetMap map is to be used as background for the map being plotted.

At this point, co-ordinate systems need to be considered. The CHOROMAP just produced used X and Y co-ordinates. The table concerned also included latitude and longitude data, but this was not used. With OPENSTREETMAP, it is essential to use latitude and longitude – hence the dropping and renaming of columns in this next example. 

The other major change in the data selection code is that, mainly for the sake of variety, tables from the MAPSGFK library are used this time. Whereas the MAPSSAS tables gave county boundaries and county names, the MAPSGFK tables for the UK give smaller regions, about 400 of them. To prevent the plot from getting too busy, WHERE clauses below select boundary data for only England and Wales, and “name” data for a small number of specific towns.

Maps in ODS Graphics Proc SGMAP Image 3

No MAPRESPDATA table is specified this time, as the regions are not to be shaded. The corresponding syntax has therefore been omitted from the CHOROMAP statement. 

The OPENSTREETMAP statement has no parameters and no options. This is because it does not support any. Proc SGMAP selects an OPENSTREETMAP background based on the other data to be plotted. There is no more direct way of controlling the geographical extent of the area chosen, or how much annotation is provided as part of this background map. The above code produces the following map:

Maps in ODS Graphics Proc SGMAP Image 4

This is impressive in some ways, but not in others. In many places the boundaries plotted by CHOROMAP have partially overwritten black text that was generated as part of the background map. One town – Preston – is so good we’ve named it twice, in black as part of the background map and in red from the TEXT command. Parts of other countries are included, plus limits of territorial waters, and so on. 

One way to influence the appearance of this map, and solve some of these problems, is to leave out the CHOROMAP statement altogether. The MAPDATA data set is still needed – without it, there would be no background map at all – but now it seems to be the PLOTDATA data set and the TEXT statement that determine the details of the background map produced by the OPENSTREETMAP statement. The result is:

Maps in ODS Graphics Proc SGMAP Image 5

The geographical area covered by the map has reduced, and there are more place names in black this time – in fact, all the ones we were particularly interested in except Bournemouth and Sevenoaks.

An ESRIMAP operates in a very similar way to an OPENSTREETMAP, for example:

Maps in ODS Graphics Proc SGMAP Image 6

Maps in ODS Graphics Proc SGMAP Image 7

Omitting the CHOROMAP statement would alter the geographical area displayed in exactly the same way for ESRIMAP as it did for OPENSTREETMAP.

The example above uses an ESRI map called World_Physical_Map. Others available include World_Terrain_Base, World_Shaded_Relief and World_Imagery. For further possibilities, please refer to the ESRI website.

The mapping facilities provided by Proc SGMAP are currently subject to a number of restrictions:

  • The procedure is not included in SAS® Viya™.
  • It cannot use data that has been processed in CAS.
  • SGE files produced are not supported by the ODS Graphics editor (although it is possible to use the ODS Graphics Editor to annotate an image file produced by Proc SGMAP).
  • SGE files produced cannot be rendered using Proc SGRENDER.
  • Output to SVG, PDF and EMF are not supported when using ESRI or OPENSTREETMAP maps.
  • There is no facility to save GTL code, and there are no corresponding GTL facilities.
  • There are no corresponding facilities in the ODS Graphics Designer.

In fact, for the present virtually all Proc SGMAP can do is produce image files of maps – but to be able to do this in Base SAS is certainly a step forward.