Hi! Just need a little help using maps.counties.
Using maps.counties as a base data set I need to remove boundaries between two adjacent counties and redraw a new boundary.
For example, in California (state 6) I need to remove the boundary between Riverside County (county 65) and Orange County (county 59) and redraw a vertical line where x = 2.0475 (so now Orange County's new border extends into Riverside).
I was thinking I could use proc gremove to remove the boundary, but how would I add the new vertical boundary at x = 2.0475? I know sort order is important, so where would this new boundary need to be placed in my counties dataset?
Thanks for any help/ hints given!
First, why are you moving the country boundary? Has the county line actually changed?
If so, you might consider using the new MAPSGFK map library (first released with 9.3m2).
Unless this is a very recent change, it should be reflected in this data.
As far as removing and adding the boundary in your current map, is isn't trivial.
Gremove can take a counties data set and remove the internal county lines and leave you with the state boundary only. It does this by having multiple variables to identify the area. One is the state and one is the county. So, to remove the line between these counties, you need a similar set of values that indicates these 2 counties are in the same larger group (like state was above).
Adding a line back is difficult. You must end up with 2 polygons and you have now created one out of the two areas. You really need to know the y and x values at each end of this new line, that is, where the new line intersects the outside polygon. And that line coordinates must be inserted into each polygons.
Looking at the example below, you have straight boundary lines. But your counties will not and there may not already be a point where you want to insert the new line. This starts after you removed the existing line and now have only one polygon.
y, x
1,3 1.5,3 2,3
-----------------------------------------------------
| A | After removing - Only have polygon "A"
| |
------------------------------------------------------
1,4 2,4
In the map data set, the data might look like this:
ID y x segment
A 1 3 1
A 2 3 1
A 2 4 1
A 1 4 1
What you need:
y,x
1,3 1.5,3 2,3
-----------------------------------------------------
| A | B | After adding new line and having 2 polygons.
| | |
------------------------------------------------------
1,4 2,4
You need to change it to, where A and B are the 2 different counties.
ID y x segment
A 1 3 1
A 1.5 3 1 <= New Line
A 1.5 4 1 <= New Line
A 1 4 1
B 1.5 3 1 <= New Line
B 2 3 1
B 2 4 1
B 1.5 4 1 <= New Line
You will probably have to add this manually using data step code.
Hope that helps.
First, why are you moving the country boundary? Has the county line actually changed?
If so, you might consider using the new MAPSGFK map library (first released with 9.3m2).
Unless this is a very recent change, it should be reflected in this data.
As far as removing and adding the boundary in your current map, is isn't trivial.
Gremove can take a counties data set and remove the internal county lines and leave you with the state boundary only. It does this by having multiple variables to identify the area. One is the state and one is the county. So, to remove the line between these counties, you need a similar set of values that indicates these 2 counties are in the same larger group (like state was above).
Adding a line back is difficult. You must end up with 2 polygons and you have now created one out of the two areas. You really need to know the y and x values at each end of this new line, that is, where the new line intersects the outside polygon. And that line coordinates must be inserted into each polygons.
Looking at the example below, you have straight boundary lines. But your counties will not and there may not already be a point where you want to insert the new line. This starts after you removed the existing line and now have only one polygon.
y, x
1,3 1.5,3 2,3
-----------------------------------------------------
| A | After removing - Only have polygon "A"
| |
------------------------------------------------------
1,4 2,4
In the map data set, the data might look like this:
ID y x segment
A 1 3 1
A 2 3 1
A 2 4 1
A 1 4 1
What you need:
y,x
1,3 1.5,3 2,3
-----------------------------------------------------
| A | B | After adding new line and having 2 polygons.
| | |
------------------------------------------------------
1,4 2,4
You need to change it to, where A and B are the 2 different counties.
ID y x segment
A 1 3 1
A 1.5 3 1 <= New Line
A 1.5 4 1 <= New Line
A 1 4 1
B 1.5 3 1 <= New Line
B 2 3 1
B 2 4 1
B 1.5 4 1 <= New Line
You will probably have to add this manually using data step code.
Hope that helps.
Thank you! Exactly what I needed. County boundaries haven't changed; just using this as a guide to annotate areas that mostly follow county lines to define specific areas of interest on a state/ county map.
Thanks again!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.