BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
akulkarni
Fluorite | Level 6

Contents:     Purpose / Requirements / Usage  / Limitations / Example / References


PURPOSE:

Creates custom region maps quickly using PROC GMAP and without having to know the intricacies of the procedure.

 

REQUIREMENTS:

Base SAS Software and SAS/GRAPH. You will first need to download the desired region shp file (For example, State, County or Zip shp file. You can download shape files here: https://www.census.gov/geo/maps-data/data/tiger-cart-boundary.html).

 

USAGE:

Download the file regmap.sas attached with this post and save it in your work directory (or any desired location). Replace the text within quotes in the following statement with the location of the %REGMAP macro definition file on your system. In your SAS program or in the SAS editor window, specify this statement to define the %REGMAP macro and make it available for use:

   %inc "<location of your file containing the REGMAP macro>";

Following this statement, you may call the %REGMAP macro.

 

The required arguments for the %REGMAP macro are as follows:

your_data=

SAS data set to be analyzed.

shp_file=

Region map shape file to output the data upon (For example, State, County or Zip shp file).

common_id=

Name of the geo variable that exists in both your data and the shape file. This will be the unique identifier of a region/location.

response_var=

Name of the variable that is to be outputted on the region map.

title= (optional)

Title for the region map.

start_color= (optional)

Starting color in the color scale.

end_color= (optional)

Ending color in the color scale.

labels= (optional)

Labels for the regions.

 

LIMITATIONS:

Labels cannot be outputted on the map as of now but it’s a work in progress.

 

EXAMPLE:

 

/*First step is to import the shape file*/

Proc MAPIMPORT OUT=State Datafile='your-location\cb_2016_us_state_20m.shp';

run;

 

/*Make sure that the common_id variable is in the same format for both your dataset and shape file.

Note that when you import a shape file, SAS creates a dataset. You may manipulate this dataset just like in the following code.*/

data State2;

set State;

STATE=input(STATEFP,BEST12.);

run;

 

/*Now you set reference to where the REGMAP macro is located*/

%inc "your-location/regmap.sas";

 

/*Lastly, just call the macro funtion that creates the map*/

%regmap(your_data=Pop,shp_file=State2,common_id=STATE, response_var=CENSUS2010POP, title="US Population",start_color=CXFF0000 ,end_color=CX00FF00);

 

REFERENCES:

SAS Support Samples & Notes: https://support.sas.com/sassamples/graphgallery/PROC_GMAP.html

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

You would need SAS/GRAPH for this as well. 

I'm assuming there is no question here, rather a sharing of code/ideas?

View solution in original post

3 REPLIES 3
Reeza
Super User

You would need SAS/GRAPH for this as well. 

I'm assuming there is no question here, rather a sharing of code/ideas?

akulkarni
Fluorite | Level 6
Thanks for reading my post! Yes, I forgot that you'd need SAS/GRAPH too if it's not already installed. I just wanted to share my code because I know it can be challenging to create region maps if you're new to SAS. I confused sascommunity.org with this website which appears to be Q&A only.
Reeza
Super User

@akulkarni wrote:
 I confused sascommunity.org with this website which appears to be Q&A only.

You can post topics/tutorials such as this, but they go under the library section. 

sas-innovate-2024.png

 

Time is running out to save with the early bird rate. Register by Friday, March 1 for just $695 - $100 off the standard rate.

 

Check out the agenda and get ready for a jam-packed event featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events. 

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1153 views
  • 1 like
  • 2 in conversation