mapimport

4月 132017
 

SAS provides a map for each country, but there are likely other maps you want to use that SAS does not provide. If you have other maps in the Esri shapefile format, you're in luck - you can import those maps and use them! In this blog post I share [...]

The post Your mapping toolkit tip #4 - importing maps into SAS appeared first on SAS Learning Post.

8月 302011
 

While talking to SAS users in Australia earlier this month, I often demonstrated the capabilities of the new Map Chart task in SAS Enterprise Guide 4.3. Creating map charts has never been easier: select your map data source, then select your response data source, and click Run. Voila! You've got a map chart.  (See this SAS Global Forum paper from Stephanie Thompson for proof that it's "easier than you think".)

Of course, all of my map chart examples used data from the United States.   Australians recognize a map of the USA when they see it (I cannot say the same of many Americans who view a map of Australia), but they wanted to see examples of maps that featured their country. And although SAS provides map data for Australia with detail to the state level, these users wanted more detail than that.   Here is an example of a "coarse-grained" map chart of Australia with just the state boundaries, created using the MAPS.AUSTRAL data set that is supplied with SAS:
Not much detail in this map of Australia

On their web site, the Australia Bureau of Statistics provides map data with more details, down to the "statistical regions", "local government regions" and more. These data files are provided as shape files in ESRI or MapInfo format.

Fortunately, it's easy to import ESRI shape files into SAS map data sets by using PROC MAPIMPORT.  Assuming you've downloaded the ESRI shape files to your local system, this simple code can convert them to a SAS map data set:

/* Shape file for statistical local areas */
proc mapimport out=aus_sla
  datafile="c:\projects\AusMaps\SLA11aAust.shp";
run;

With the map data now available in WORK.AUS_SLA, all you need is some response data that contains a shared identifier field.  The following step creates a data source with random values:

/* make up some response data */
data response_sla;
  set aus_sla (keep=SLA_CODE11 SLA_NAME11);
	/* keep just one value per region */
	by SLA_CODE11;
	if first.SLA_CODE11;
	/* random value between 0 and 100 */
	RespValue = ranuni(0) * 100;
run;

Now use the GMAP procedure to combine the two data sources into a colorful, if somewhat meaningless, map of Australia:

/* create a simple map chart by combining the two */
legend1 across=3 label=("Values");
goptions colors=(green blue purple red orange yellow );
proc gmap data=work.response_sla map=work.aus_sla all;
	id sla_code11;
	choro RespValue / levels=6
		woutline=1
		legend=legend1
		;
run;
quit;

Here is a sample of the output (Americans, take note):
A sample map chart with more detail for Australia

Just remember: Map Charts = Map Data + Your Response Data.  With a third data set for annotations, you can create even fancier results.  But that's a topic for another blog post.  For those readers who are curious in the meantime, a simple SAS support search will open the door for you.