Calcite | Level 5

## How to plot a set of unique coordinates on a map

I want to plot unique coordinates on the example map shown at: https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/grmapref/n1reiydhvbvs7rn1lxrlps7gwt3l.htm

I would appreciate code to add to that below that places a point on the map generated by the code below.

data us48;
set mapsgfk.us_states;
if state not in (2 15 72);
run;

proc gproject data=us48
latlon
degrees eastlong
out=gulf
longmin=-98
longmax=-81
latmin=25
latmax=33;
where density<5;
id state;
run;

title "Northern Gulf Coast";
pattern value=mempty color=blue;
proc gmap map=gulf data=gulf all;
id state;
choro state / statistic=first nolegend levels=1;
run;
quit;

goptions reset=all;

1 ACCEPTED SOLUTION

Accepted Solutions
Meteorite | Level 14

## Re: How to plot a set of unique coordinates on a map

Ahh - I forgot one thing in the gproject. I had specified the parmin= dataset, but I forgot to tell gproject which entry in that dataset to use.  Here's the new/fixed code:

``````data coordinates;
input lat long;
datalines;
28.9787 -95.1672
29.1468 -94.8645
29.2313 -89.8375
29.4695 -94.0852
29.5513 -92.899
29.5282 -93.9293
29.016 -95.098
29.8865 -88.1793
29.5088 -93.9617
29.4177 -92.587
29.1007 -94.02
29.5347 -93.5135
25.2593 -81.9585
28.9765 -91.7018
28.1155 -93.6067
28.3387 -94.4748
28.9765 -91.7018
;
run;

data us48;
set mapsgfk.us_states;
if state not in (2 15 72);
run;

proc gproject data=us48 out=gulf
latlon degrees eastlong
longmin=-98
longmax=-68
latmin=25
latmax=36.5
parmout=projparm;
where density<5;
id state;
run;
/* project the coordinates using the same projection parameters as were used to project the map */
proc gproject data=coordinates out=coordinates
latlon degrees eastlong
longmin=-98
longmax=-68
latmin=25
latmax=36.5
parmin=projparm parmentry=gulf;
id;
run;
/* convert the projected coordinates into annotate dataset */
data coordinates; set coordinates;
xsys='2'; ysys='2'; hsys='3'; when='a';
function='pie'; rotate=360; size=1.0; color='red';
run;

title "US Southern Atlantic and Gulf of Mexico";
pattern value=mempty color=blue;
proc gmap map=gulf data=gulf all anno=coordinates;
id state;
choro state / statistic=first nolegend levels=1;``````

13 REPLIES 13
Super User

## Re: How to plot a set of unique coordinates on a map

In GMAP you use annotate method, which is annoying IMO.

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/grmapref/p0nzqxp7w0l5vsn152fk3nl66qvc.htm

I would recommend SGMAP instead, set the bubble size to a fixed value in the data set to have just points.

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/grmapref/p0posjqhzkf0xkn0zz0i8b1iq4fz.htm

You can find more examples at lexjansen.com and robslink

Calcite | Level 5

## Re: How to plot a set of unique coordinates on a map

Thanks Reeza:
Unfortunately, I'm just not bright enough to modify the code shown at the
url's you have kindly provided for my purposes.
Could you possibly help me by further modifying the code below to place the
(water) locations on the map that emerges from the code below?
Sorry, but I just can't seem to make any progress.
j
*--------------------*
*Locations*

28.9787 -95.1672
29.1468 -94.8645
29.2313 -89.8375
29.4695 -94.0852
29.5513 -92.899
29.5282 -93.9293
29.016 -95.098
29.8865 -88.1793
29.5088 -93.9617
29.4177 -92.587
29.1007 -94.02
29.5347 -93.5135
25.2593 -81.9585
28.9765 -91.7018
28.1155 -93.6067
28.3387 -94.4748
28.9765 -91.7018
*SAS Code*

goptions reset=all border device=png;

data us48;
set mapsgfk.us_states;
if state not in (2 15 72);
run;

proc gproject data=us48
latlon
degrees eastlong
out=gulf
longmin=-98
longmax=-68
latmin=25
latmax=36.5;
where density<5;
id state;
run;

title "US Southern Atlantic and Gulf of Mexico";
pattern value=mempty color=blue;
proc gmap map=gulf data=gulf all;
id state;
choro state / statistic=first nolegend levels=1;
run;
quit;

goptions reset=all;
goptions reset=all border device=png;

data us48;
set mapsgfk.us_states;
if state not in (2 15 72);
run;

proc gproject data=us48
latlon
degrees eastlong
out=gulf
longmin=-98
longmax=-68
latmin=25
latmax=36.5;
where density<5;
id state;
run;

title "US Southern Atlantic and Gulf of Mexico";
pattern value=mempty color=blue;
proc gmap map=gulf data=gulf all;
id state;
choro state / statistic=first nolegend levels=1;
run;
quit;

goptions reset=all;

Super User

## Re: How to plot a set of unique coordinates on a map

Calcite | Level 5

## Re: How to plot a set of unique coordinates on a map

Thanks Ksharp:
Unfortunately, I'm just not bright enough to modify the code shown at the
url's you have kindly provided for my purposes.
Could you possibly help me by further modifying the code below to place the
(water) locations on the map that emerges from the code below?
Sorry, but I just can't seem to make any progress.
j
*--------------------*
*Locations*

28.9787 -95.1672
29.1468 -94.8645
29.2313 -89.8375
29.4695 -94.0852
29.5513 -92.899
29.5282 -93.9293
29.016 -95.098
29.8865 -88.1793
29.5088 -93.9617
29.4177 -92.587
29.1007 -94.02
29.5347 -93.5135
25.2593 -81.9585
28.9765 -91.7018
28.1155 -93.6067
28.3387 -94.4748
28.9765 -91.7018

*SAS Code*

goptions reset=all border device=png;

data us48;
set mapsgfk.us_states;
if state not in (2 15 72);
run;

proc gproject data=us48
latlon
degrees eastlong
out=gulf
longmin=-98
longmax=-68
latmin=25
latmax=36.5;
where density<5;
id state;
run;

title "US Southern Atlantic and Gulf of Mexico";
pattern value=mempty color=blue;
proc gmap map=gulf data=gulf all;
id state;
choro state / statistic=first nolegend levels=1;
run;
quit;

goptions reset=all;
goptions reset=all border device=png;

data us48;
set mapsgfk.us_states;
if state not in (2 15 72);
run;

proc gproject data=us48
latlon
degrees eastlong
out=gulf
longmin=-98
longmax=-68
latmin=25
latmax=36.5;
where density<5;
id state;
run;

title "US Southern Atlantic and Gulf of Mexico";
pattern value=mempty color=blue;
proc gmap map=gulf data=gulf all;
id state;
choro state / statistic=first nolegend levels=1;
run;
quit;

goptions reset=all;

Super User

## Re: How to plot a set of unique coordinates on a map

Sorry. I am not familiar with SAS/Graph.

Maybe @GraphGuy (a.k.a  Robert.Allision) could give you a hand.

Meteorite | Level 14

## Re: How to plot a set of unique coordinates on a map

Here's a chapter I wrote on this topic, that might help:

Meteorite | Level 14

## Re: How to plot a set of unique coordinates on a map

This code should get you started ...

``````data coordinates;
input lat long;
datalines;
28.9787 -95.1672
29.1468 -94.8645
29.2313 -89.8375
29.4695 -94.0852
29.5513 -92.899
29.5282 -93.9293
29.016 -95.098
29.8865 -88.1793
29.5088 -93.9617
29.4177 -92.587
29.1007 -94.02
29.5347 -93.5135
25.2593 -81.9585
28.9765 -91.7018
28.1155 -93.6067
28.3387 -94.4748
28.9765 -91.7018
;
run;

data us48;
set mapsgfk.us_states;
if state not in (2 15 72);
run;

proc gproject data=us48 out=gulf
latlon degrees eastlong
longmin=-98
longmax=-68
latmin=25
latmax=36.5
parmout=projparm;
where density<5;
id state;
run;
/* project the coordinates using the same projection parameters as were used to project the map */
proc gproject data=coordinates out=coordinates
latlon degrees eastlong
longmin=-98
longmax=-68
latmin=25
latmax=36.5
parmin=projparm;
id;
run;
/* convert the projected coordinates into annotate dataset */
data coordinates; set coordinates;
xsys='2'; ysys='2'; hsys='3'; when='a';
function='pie'; rotate=360; size=1.0; color='red';
run;

title "US Southern Atlantic and Gulf of Mexico";
pattern value=mempty color=blue;
proc gmap map=gulf data=gulf all anno=coordinates;
id state;
choro state / statistic=first nolegend levels=1;
``````

Calcite | Level 5

## Re: How to plot a set of unique coordinates on a map

Thanks you so much, Graph Guy. Really helps novices like me figure this stuff out.

The lat-lon coordinates should be in the water versus on the land.

Is this a projection problem?

Thanks again.

j

Calcite | Level 5

## Re: How to plot a set of unique coordinates on a map

Hi GraphGuy:
I get the three warnings below (in blue).
j
---------------------
NOTE: There were 1097 observations read from the data set WORK.GULF.
WHERE resolution<=4;
NOTE: There were 17 observations read from the data set WORK.COORDINATES.
NOTE: PROCEDURE GMAP used (Total process time):
real time 57:55.91
cpu time 2.96 seconds

320 data coordinates;
321 input lat long;
322 datalines;

NOTE: The data set WORK.COORDINATES has 17 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds

340 ;
341 run;
342
343
344
345 data us48;
346 set mapsgfk.us_states;
347 if state not in (2 15 72);
348 run;

NOTE: There were 33570 observations read from the data set
MAPSGFK.US_STATES.
NOTE: The data set WORK.US48 has 17692 observations and 13 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

349
350 proc gproject data=us48 out=gulf
351 latlon degrees eastlong
352 longmin=-98
353 longmax=-68
354 latmin=25
355 latmax=36.5
356 parmout=projparm;
357 where density<5;
358 id state;
359 run;

NOTE: PARALLEL1 = 27.875.
NOTE: PARALLEL2 = 33.625.
NOTE: MERIDIAN = -83.
NOTE: The data set WORK.PROJPARM has 1 observations and 9 variables.
NOTE: The data set WORK.GULF has 1976 observations and 13 variables.
NOTE: PROCEDURE GPROJECT used (Total process time):
real time 0.03 seconds
cpu time 0.03 seconds

360 /* project the coordinates using the same projection parameters as
were used to project the map
360! */
361 proc gproject data=coordinates out=coordinates
362 latlon degrees eastlong
363 longmin=-98
364 longmax=-68
365 latmin=25
366 latmax=36.5
367 parmin=projparm;
368 id;
369 run;

WARNING: No entry named COORDINATES found in parameter data set
WORK.PROJPARM.
WARNING: The map data are completely contained within the specified
clipping region.
WARNING: Data NOT clipped due to reasons noted above.
NOTE: PARALLEL1 = 26.4161.
NOTE: PARALLEL2 = 28.7297.
NOTE: MERIDIAN = -88.56285.
NOTE: The data set WORK.COORDINATES has 17 observations and 4 variables.
NOTE: PROCEDURE GPROJECT used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds

370 /* convert the projected coordinates into annotate dataset */
371 data coordinates; set coordinates;
372 xsys='2'; ysys='2'; hsys='3'; when='a';
373 function='pie'; rotate=360; size=1.0; color='blue';
374 run;

NOTE: There were 17 observations read from the data set WORK.COORDINATES.
NOTE: The data set WORK.COORDINATES has 17 observations and 12 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

375
376 title "US Southern Atlantic and Gulf of Mexico";
377 pattern value=mempty color=black;
378 proc gmap map=gulf data=gulf all anno=coordinates;
379 id state;
380 choro state / statistic=first nolegend levels=1; run;

NOTE: 50456 bytes written to C:\Users\JOE~1.SER\AppData\Local\Temp\1\SAS
Temporary
Files\_TD17660_SECML4380988JSE_\gmap7.png.
Calcite | Level 5

## Re: How to plot a set of unique coordinates on a map

Thanks so much! Sorry to be a pest, but the points on the map should be on water versus on land.

Perhaps this problem is related to the warnings (bolded) in the sas log below?

---------------

NOTE: There were 1097 observations read from the data set WORK.GULF.
WHERE resolution<=4;
NOTE: There were 17 observations read from the data set WORK.COORDINATES.
NOTE: PROCEDURE GMAP used (Total process time):
real time 57:55.91
cpu time 2.96 seconds

320 data coordinates;
321 input lat long;
322 datalines;

NOTE: The data set WORK.COORDINATES has 17 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds

340 ;
341 run;
342
343
344
345 data us48;
346 set mapsgfk.us_states;
347 if state not in (2 15 72);
348 run;

NOTE: There were 33570 observations read from the data set MAPSGFK.US_STATES.
NOTE: The data set WORK.US48 has 17692 observations and 13 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

349
350 proc gproject data=us48 out=gulf
351 latlon degrees eastlong
352 longmin=-98
353 longmax=-68
354 latmin=25
355 latmax=36.5
356 parmout=projparm;
357 where density<5;
358 id state;
359 run;

NOTE: PARALLEL1 = 27.875.
NOTE: PARALLEL2 = 33.625.
NOTE: MERIDIAN = -83.
NOTE: The data set WORK.PROJPARM has 1 observations and 9 variables.
NOTE: The data set WORK.GULF has 1976 observations and 13 variables.
NOTE: PROCEDURE GPROJECT used (Total process time):
real time 0.03 seconds
cpu time 0.03 seconds

360 /* project the coordinates using the same projection parameters as were used to project the map
360! */
361 proc gproject data=coordinates out=coordinates
362 latlon degrees eastlong
363 longmin=-98
364 longmax=-68
365 latmin=25
366 latmax=36.5
367 parmin=projparm;
368 id;
369 run;

WARNING: No entry named COORDINATES found in parameter data set WORK.PROJPARM.
WARNING: The map data are completely contained within the specified clipping region.
WARNING: Data NOT clipped due to reasons noted above.
NOTE: PARALLEL1 = 26.4161.
NOTE: PARALLEL2 = 28.7297.
NOTE: MERIDIAN = -88.56285.
NOTE: The data set WORK.COORDINATES has 17 observations and 4 variables.
NOTE: PROCEDURE GPROJECT used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds

370 /* convert the projected coordinates into annotate dataset */
371 data coordinates; set coordinates;
372 xsys='2'; ysys='2'; hsys='3'; when='a';
373 function='pie'; rotate=360; size=1.0; color='blue';
374 run;

NOTE: There were 17 observations read from the data set WORK.COORDINATES.
NOTE: The data set WORK.COORDINATES has 17 observations and 12 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

375
376 title "US Southern Atlantic and Gulf of Mexico";
377 pattern value=mempty color=black;
378 proc gmap map=gulf data=gulf all anno=coordinates;
379 id state;
380 choro state / statistic=first nolegend levels=1; run;

NOTE: 50456 bytes written to C:\Users\JOE~1.SER\AppData\Local\Temp\1\SAS Temporary
Files\_TD17660_SECML4380988JSE_\gmap7.png.

Meteorite | Level 14

## Re: How to plot a set of unique coordinates on a map

Ahh - I forgot one thing in the gproject. I had specified the parmin= dataset, but I forgot to tell gproject which entry in that dataset to use.  Here's the new/fixed code:

``````data coordinates;
input lat long;
datalines;
28.9787 -95.1672
29.1468 -94.8645
29.2313 -89.8375
29.4695 -94.0852
29.5513 -92.899
29.5282 -93.9293
29.016 -95.098
29.8865 -88.1793
29.5088 -93.9617
29.4177 -92.587
29.1007 -94.02
29.5347 -93.5135
25.2593 -81.9585
28.9765 -91.7018
28.1155 -93.6067
28.3387 -94.4748
28.9765 -91.7018
;
run;

data us48;
set mapsgfk.us_states;
if state not in (2 15 72);
run;

proc gproject data=us48 out=gulf
latlon degrees eastlong
longmin=-98
longmax=-68
latmin=25
latmax=36.5
parmout=projparm;
where density<5;
id state;
run;
/* project the coordinates using the same projection parameters as were used to project the map */
proc gproject data=coordinates out=coordinates
latlon degrees eastlong
longmin=-98
longmax=-68
latmin=25
latmax=36.5
parmin=projparm parmentry=gulf;
id;
run;
/* convert the projected coordinates into annotate dataset */
data coordinates; set coordinates;
xsys='2'; ysys='2'; hsys='3'; when='a';
function='pie'; rotate=360; size=1.0; color='red';
run;

title "US Southern Atlantic and Gulf of Mexico";
pattern value=mempty color=blue;
proc gmap map=gulf data=gulf all anno=coordinates;
id state;
choro state / statistic=first nolegend levels=1;``````

Calcite | Level 5

## Re: How to plot a set of unique coordinates on a map

Fantastic! Your help is deeply appreciated. Thanks so much. Now that I have working code , I can try to understand it!

j

Meteorite | Level 14

## Re: How to plot a set of unique coordinates on a map

I have a couple of similar examples on this page, that might interest you. (they're on the last row of thumbnails - bottom/left):