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

I am using the GMAP procedure to map out specific locations in a state, but would also like to add 4 specific cities to the map as a reference.  I have the locations of interest as part of the annotate set, and the cities (from the us_cities data) in the other part.  I want stars as the markers for the points of interest and just circles or dots as the markers for the 4 cities.  Here is my code.  I can only get the points of interest to show on my map.   I cannot get the cities two show up at all. I am using 9.4.

 

data Maine;
   set maps.states;
   if state =stfips("ME");
run;



data CITIES;
input City $1-25;
datalines;
PORTLAND
BANGOR
AUGUSTA
CARIBOU
;
RUN;



proc sql; create table ME_CITIES  as
select a.*, "BBL" as color
from maps.uscity A 
where a.State = stfips("ME") and upper(a.City) in (select trim(b.City) from CITIES b);
quit;

 
proc sql;create table ME_1 as
select a.prop_id, a.prop_name, a.total_unit_cnt, 
case when a.Color = 'R' then 'Red' when a.Color = 'Y' then 'BIOY' when a.Color = 'G' then 'Green' end
 as color,
b.state2kx as state, b.std_st as statecode, b.lat as Y, b.lon as X,
b.lat as lat, b.lon as long,
case when a.Color = 'R' then 'High Risk' when a.Color = 'Y' then 'Medium Risk' when a.Color = 'G' then 'Low Risk' end
as risk_category 
from RISK_LIST a LEFT JOIN raw.PROP_INFO b ON a.PROP_ID = b.property_id;
quit;

/*if cities have a unit of altitude, other data will have . */
data anno1; set ME_1 ME_CITIES; length text $25.; xsys='2'; ysys='2'; hsys='3'; when='a'; x= -x *(atan(1)/45); y = y* (atan(1)/45); function = 'label'; if alt = . then style = 'special' ; else style = 'swissb'; if alt = . then text = 'M'; else text = city; color = color ; if alt = . then size = 3; else size = 5; position = '5'; run; data combined; set maine anno1; run; proc gproject data = COMBINED degrees out = COMBINED1; id state; run; data MAP ANNO ; set COMBINED1; if density = . then output ANNO; else output MAP; run; ods results off; ods html close; goptions reset=all device=jpeg /*cback=cx004488*/ ; pattern1 v=solid c=cxeeeee6 r=50; ; ; proc gmap data = map map = map anno = Anno ; id state; choro state / coutline = cx739436 des = "Properties" nolegend; run; quit; ods listing close;
1 ACCEPTED SOLUTION

Accepted Solutions
GraphGuy
Meteorite | Level 14

Here's how I would recommend doing it:

 

%let name=map;
filename odsout '.';

goptions device=png;
goptions noborder;
 
ODS LISTING CLOSE;
ODS HTML path=odsout body="&name..htm" style=htmlblue;

goptions gunit=pct htitle=6 ftitle="albany amt/bold" htext=4.25 ftext="albany amt/bold";
goptions ctext=gray33;

data readings;
input value lat long;
datalines;
200 45.2998937 -69.283683
250 44.8327587 -70.5181767
225 44.7882013 -67.6611867
;
run;

data cities;
input city $1-25;
statecode="ME";
datalines;
PORTLAND
BANGOR
AUGUSTA
CARIBOU
;
run;

/* merge in the lat/long for each city */
proc sql;
create table cities as
select cities.*, uscity.lat, uscity.long
from cities left join mapsgfk.uscity
on upcase(cities.city)=upcase(uscity.city) and cities.statecode=uscity.statecode;
quit; run;

/* get the map, and project it, and save the projection parameters */
data maine_map; set mapsgfk.us_states (where=(statecode="ME"));
run;
proc gproject data=maine_map out=maine_map latlong eastlong degrees
 parmout=projparm;
id statecode;
run;

/* project the city lat/long's, using the same projection parameters */
proc gproject data=cities out=cities latlong eastlong degrees
 parmin=projparm parmentry=maine_map;
id;
run;

data anno_cities; set cities;
length function $8 color $12 style $35;
xsys='2'; ysys='2'; hsys='3'; when='a';
function='pie'; rotate=360; size=1.5; style='psolid'; color='red';
run;

/* project the city lat/long's, using the same projection parameters */
proc gproject data=readings out=readings latlong eastlong degrees
 parmin=projparm parmentry=maine_map;
id;
run;

data anno_readings; set readings;
length function $8 color $12 style $35;
xsys='2'; ysys='2'; hsys='3'; when='a';
function='label'; position='5';
size=5.0; color='dodgerblue';
style='marker'; text='V'; /* 'star' from sas/graph marker software font */
run;

/* combine the annotate datasets */
data anno_all; set anno_cities anno_readings;
run;


pattern1 v=s c=cxeeeee6;

proc gmap data=maine_map map=maine_map anno=anno_all;
id statecode;
choro statecode / nolegend coutline=cx739436
 des='Properties' name="&name";
run;

proc print data=cities; run;
proc print data=readings; run;

quit;
ODS HTML CLOSE;
ODS LISTING;

 

map.png 

View solution in original post

3 REPLIES 3
GraphGuy
Meteorite | Level 14

Here's how I would recommend doing it:

 

%let name=map;
filename odsout '.';

goptions device=png;
goptions noborder;
 
ODS LISTING CLOSE;
ODS HTML path=odsout body="&name..htm" style=htmlblue;

goptions gunit=pct htitle=6 ftitle="albany amt/bold" htext=4.25 ftext="albany amt/bold";
goptions ctext=gray33;

data readings;
input value lat long;
datalines;
200 45.2998937 -69.283683
250 44.8327587 -70.5181767
225 44.7882013 -67.6611867
;
run;

data cities;
input city $1-25;
statecode="ME";
datalines;
PORTLAND
BANGOR
AUGUSTA
CARIBOU
;
run;

/* merge in the lat/long for each city */
proc sql;
create table cities as
select cities.*, uscity.lat, uscity.long
from cities left join mapsgfk.uscity
on upcase(cities.city)=upcase(uscity.city) and cities.statecode=uscity.statecode;
quit; run;

/* get the map, and project it, and save the projection parameters */
data maine_map; set mapsgfk.us_states (where=(statecode="ME"));
run;
proc gproject data=maine_map out=maine_map latlong eastlong degrees
 parmout=projparm;
id statecode;
run;

/* project the city lat/long's, using the same projection parameters */
proc gproject data=cities out=cities latlong eastlong degrees
 parmin=projparm parmentry=maine_map;
id;
run;

data anno_cities; set cities;
length function $8 color $12 style $35;
xsys='2'; ysys='2'; hsys='3'; when='a';
function='pie'; rotate=360; size=1.5; style='psolid'; color='red';
run;

/* project the city lat/long's, using the same projection parameters */
proc gproject data=readings out=readings latlong eastlong degrees
 parmin=projparm parmentry=maine_map;
id;
run;

data anno_readings; set readings;
length function $8 color $12 style $35;
xsys='2'; ysys='2'; hsys='3'; when='a';
function='label'; position='5';
size=5.0; color='dodgerblue';
style='marker'; text='V'; /* 'star' from sas/graph marker software font */
run;

/* combine the annotate datasets */
data anno_all; set anno_cities anno_readings;
run;


pattern1 v=s c=cxeeeee6;

proc gmap data=maine_map map=maine_map anno=anno_all;
id statecode;
choro statecode / nolegend coutline=cx739436
 des='Properties' name="&name";
run;

proc print data=cities; run;
proc print data=readings; run;

quit;
ODS HTML CLOSE;
ODS LISTING;

 

map.png 

RandoDando
Pyrite | Level 9
Thank you Rob. I will try that. By the way, I have a few markers which are close together and overlap. The markers are color-coded as Green, Yellow and Red (with Red being the most important). Is there any way to set a transparent color scheme or some kind of priority for the colors where red always shows on the top, and yellow on top of green?
GraphGuy
Meteorite | Level 14

You can sort your annotate data, such that the things you want to show up 'on top' are last in the dataset, and then they will be drawn last (and show up on top) of the other annotated graphics.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 940 views
  • 2 likes
  • 2 in conversation