BookmarkSubscribeRSS Feed
gfarkas
Calcite | Level 5

Hi all,

I'm trying to figure out how to draw several lines between different pairs of points on a map, using PROC GMAP or some other mapping procedure. I've already done the prep work using PROC GPROJECT to get my annotation dataset projected in line with my source map dataset, and I can display my map and points with:

proc gmap data=States map=Map0 ;

id state;

choro state / annotate=Loc1 discrete nolegend;

run; quit;

In that code,

States comes from maps.states(where=(state not in(2 15 72))), it's basically the continental US.

Map0 comes from States, and then is processed similar to the dataset "Map" in this example: SAS Maps Online

Loc1 is my dataset of various coordinates I've plotted, and was processed similar to the dataset "Cities" in that same example. It has 30 records of coordinates, with a variable LocID numbered 1 through 30, which is how we identify them internally.

So far so good, and all the points in Loc1 come out exactly where they should be. Now, I'd like to be able to draw lines between the point with LocID=1 and LocID=2, or LocID=5 and LocID=7, or LocID=9 and LocID=22, and so on.

I haven't been able to figure out how to do this, either through PROC GMAP or some other mapping procedure. Does anyone have any suggestions for me to try or examples I could follow?

Thanks!

8 REPLIES 8
GraphGuy
Meteorite | Level 14

You can use an 'annotate' data set to place markers on the map (annotated function='pie') and connect them using annotated lines (function='move' and 'draw').

Here is the simplest example I have...

UPS Tracking Map (SAS/Graph gmap)

http://robslink.com/SAS/democd41/ups_tracking_map_info.htm

gfarkas
Calcite | Level 5

That's great, thanks so much! I was able to follow that example and get it to work:

gmap5.png

Now, the next thing I need to figure out is if there's a way to calculate the distances of those line segments. That would probably take some data manipulation and using the GEODIST function, right? Or is there a way to do it within PROC GMAP or one of the other mapping procedures?

Thanks again!

GraphGuy
Meteorite | Level 14

You can use Geodist, but you'll need to make the calculations on the lat/long values *before* you project them.

gfarkas
Calcite | Level 5

One other thing... is there a way to offset multiple lines that collect the same 2 points? For example, if these represent travel between 2 cities, and someone travels between the same two cities more than once, can there be multiple lines next to each other but slightly offset?

GraphGuy
Meteorite | Level 14

There is a way to offset text, using the annotate 'position' (position='5', position='2', etc), but there is not a built-in way to apply offsets to the drawn graphics (such as pie markers and lines/arrows).  You will have to programmatically manipulate the x/y coordinates in your data to do that.  (I think this will not be easy.)

ballardw
Super User

Unless the number of trips is large, you might be able to summarize your data and get counts of duplicate trips. Then factor the number into a line width parameter.

gfarkas
Calcite | Level 5

Thanks to both of you for your responses. What you wrote makes sense, and is along the lines of what I was thinking... it's good to get confirmation on it, definitely.

GraphGuy
Meteorite | Level 14

Another option, besides the width or color of the line, would be to use alpha-transparent colors (if you have SAS 9.3 or higher).  With the alpha-transparent colors, the more lines you overlay in the same location, the more color they will get.

An example of a red alpha-transparent color would be ...  Aff000077

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 8 replies
  • 6973 views
  • 0 likes
  • 3 in conversation