In a previous article, I discussed how to use PROC GPROJECT to project and re-project spatial data. However, that’s not all that the GPROJECT procedure can be used for! In this article, I’ll discuss how you can use PROC GPROJECT to clip out a specific geographic extent from a larger dataset, allowing you to create precise maps that focus on a defined study area.
Imagine you are working on a project focusing specifically on the northeast United States. You need to create a map highlighting this region, but you only have a map data set that covers the entire country. Rather than going back to the drawing board and trying to find a new map data set that focuses on just your study area, you can simply clip your existing map data set to a specific geographic extent.
Select any image to see a larger version.
Mobile users: To view the images, select the "Full" version at the bottom of the page.
When using the GPROJECT procedure to project spatial data, you use the PROJECT= option to specify what projection to use: Lambert, Albers, Gnomonic, or Proj4. However, there is a fifth option: none.
You can then use the LONGMIN=, LONGMAX=, LATMIN=, and LATMAX= options to specify the geographic extent that you want to clip. The latitude and longitude values that you provide here determine the rectangle that is clipped from the input data.
PROC GPROJECT DATA=input-mapdata-set
<OUT=output-map-data-set>
DEGREES
EASTLONG
PROJECT=none
LONGMIN=min-longitude
LONGMAX=max-longitude
LATMIN=min-latitude
LATMAX=max-latitude;
ID <id-variable(s)>;
RUN;
Let’s look at an example. Imagine that I have a map data set covering the entire United States. Using the SGMAP procedure, I could create a map that looks like this:
However, I need to create a map focused on just the northeastern region of the country. To do so, I’ll use the LONGMIN, LONGMAX, LATMIN, and LATMAX options to define the region that I want to clip. I’ll specify the latitude parallels that define the northern and southern bounds of my study area, and the longitude values (or meridians) that define the eastern and western bounds. Because my input data set is unprojected, I’ll refer to unprojected latitude and longitude values in the GPROJECT procedure.
proc gproject data=states
out=NE_States
degrees eastlong
project=none
longmin=-80
longmax=-60
latmin=40
latmax=75;
id StateCode;
run;
This will create a clipped map data set, where the northern boundary is 75 degrees latitude, the southern boundary is 40 degrees latitude, the eastern boundary is -80 degrees longitude, and the western boundary is -60 degrees longitude.
This new, clipped map data set can then be used to create more precise maps, focused just on this particular study area.
When creating a map or performing spatial analysis, your map data set may not always line up exactly with your study area. However, using the GPROJECT procedure, it’s easy to trim or clip a map dataset to a specific geographic extent.
Find more articles from SAS Global Enablement and Learning here.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.