BookmarkSubscribeRSS Feed
rcleven2
Obsidian | Level 7
data Active_patients (rename=(cw_state=state death=dateofdeath close=dateclosed zipc=zip ));
	length first $40;
	length last $40;
	length cw_state $2;
	drop  first_name state dateofdeath date_death dateclosed date_clos zip 'HIV Date'n 'Enrl Date'n;
	retain urn last first middle;
	set hivcc."Grey's Active Patients List$"n;
	last=propcase(scan(name,1," ,-"));
	first_name=propcase(scan(name,-1,","));
	first=propcase(scan(first_name,1," "));
	middle=propcase(scan(first_name,2," "));
	hivdate=input('HIV Date'n,mmddyy10.);
	enrldate=input('Enrl Date'n,mmddyy10.);
	date_death=scan(dateofdeath,1," ");
	death=input(date_death,mmddyy10.);
	date_clos=scan(dateclosed,1," ");
	close=input(date_clos,mmddyy10.);
	format close death hivdate enrldate mmddyy10.;
	zipc=input(zip,5.);
	if state = "Georgia" then cw_state = "GA";
		else if state = "Tennessee" then cw_state = "TN";
		else if state = "Florida" then cw_state = "GA";
	if county = " " then county = "Whitfield";
	if county = "De Kalb" then county="DeKalb";
run; 


proc sort data=work.active_patients;
	by urn;
run;
proc sort data=newadd.'''Print 1 - Data Set WORK#BAD_$'''n out=new_add;
	by urn;
run;
proc sort data=newadd2.'''Print 1 - Data Set WORK#BAD_$'''n out=new_add2;
	by urn;
run;


data updated_addresses(rename=(state=statecode county=county_name));
	merge work.active_patients work.new_add work.new_add2;
	by urn;
run;


proc sort data=updated_addresses nodupkey;
	by urn;
run;
proc sort data=updated_addresses;
	by statecode county_name;
run;


proc sort data=mapsgfk.us_counties_attr out=county_fips(rename=(idname=county_name)) ;
	by statecode idname;
	where state=13;
run;


data new_list (rename=(statecode=state state=state_fips));
	length patient_type $1;
	length point $1;
	length county_name $55;
	merge  work.updated_addresses(in=a) work.county_fips(keep=county county_name state statecode in=b);
	by statecode county_name;
	if b and not a then delete;
	if state ne 13 then delete;
	if year(hivdate)=2017 then do;
					patient_type="1";
					point='L';
				end;

		else if year(hivdate)<=2016 and year(enrldate)=2017 then do;
					patient_type="2";
					point='M';
				end;
		
		else if year(hivdate)<=2016 and year(enrldate)<=2016 then do;
					patient_type="3";
					point='J';
				end;
run;
/*****************************************************************************************************/
/* NOTE!!!! Instert Data provided here into the data= portion of Proc Geocode */

proc geocode data=work.new_list lookupstreet=maps.usm out=geocoded method=street ;
run; 


options mprint;
%helpano(all)
%annomac()
data annotate_dots(keep=x y state_fips county _status_ name when text color style size xsys ysys hsys rename=(state_fips=state));
	%dclanno
	length text $60;
	length state_fips 5; 
	set geocoded(rename=(m_state=stname) drop=state);
	where _status_="Found";
/*	LABEL(x1, y1, text, color, ang, rot, ht, font, pos)*/
	%system(2,2,1);
	when='a';
	if patient_type="1" then color='crimson';
		else if patient_type="2" then color='gold';
		else if patient_type="3" then color='lip';
	%label(x,y,point,*,0,0,4,'Special',5);
	if color='crimson' then size=5;
	output;	
run;


proc sort data=annotate_dots;
	by descending color;
run;


data gacounties(rename=(long=x lat=y));
 	set mapsgfk.us_counties(drop=x y where=(state=13));
run; 
/* Combine datasets */
data all;
	set gacounties annotate_dots; 
run; 

		/* project the data */ 
		proc gproject data=all out=allp dupok degree eastlong; 
			id state county; 
		run; 

				/* separate the annotate and map data sets */ 
				data map anno; 
					set allp; 
					if when='a' then output anno; 
						else output map; 
				run; 
						/* Subset dataset to be graphed */
						data district_anno;
							set anno;
							if county = 115 then delete;
							if county in(57 111 123 213 227 313) then output;
								else if county not in(57 111 123 213 227 313) and color='crimson' then output;	
						run;

data districtmap;
	set map;
	where county in(57 111 123 213 227 313);
run;

data anno_legend;
	%dclanno
	length text $50;
	%system(3,3,1);
	%label(3,15,'L',crimson,0,0,6,'Special',5);
	%label(5,15,'New Positive',black,0,0,4,'Thorndale AMT',6);
	%label(3,10,'M',gold,0,0,6,'Special',5);
	%label(5,10,'New to TLBC',black,0,0,4,'Thorndale AMT',6);
	%label(3,5,'J',lip,0,0,6,'Special',5);
	%label(5,5,'Previously Entered into Care',black,0,0,4,'Thorndale AMT',6);
	output;
run;



goptions reset=all device=png;
ods html path="c:\users\rgclevenger\desktop\Maps" (url=none) file="hiv_map.html"   ;
 

	proc gmap data=districtmap map=districtmap all anno=anno ;
		id state county;
		choro state / nolegend;
		pattern1 v=s c=cornflowerblue;	
	run;

	proc gmap data=districtmap map=districtmap all anno=district_anno ;
		id state county;
		choro state /  nolegend anno=anno_legend;			
		pattern1 v=s c=lig;
	run;

ods html close;
ods listing;

Using Proc Gmap I have geocoded and projected my maps and annotations correctly. Now all that I am trying to do to finalize this project is get the names of the individual plotted points to show up when I hover over them with my mouse.  I have supplied my entire code and a sample set of data that anyone can use.

 

Help me Obi-Wan, you are my only hope. 

 

BONUS POINTS if anyone can tell me why I keep getting this warning message and how to fix it. My OCD can't stand seeing Warning messages. 

----WARNING: Some observations were discarded when charting STATE. Only first
matching observation was used. Use STATISTIC= option for summary
statistics.

5 REPLIES 5
ballardw
Super User

This is easy:

BONUS POINTS if anyone can tell me why I keep getting this warning message and how to fix it. My OCD can't stand seeing Warning messages. 

----WARNING: Some observations were discarded when charting STATE. Only first
matching observation was used. Use STATISTIC= option for summary
statistics

Your code

proc gmap data=districtmap map=districtmap 

using the data=  dataset the same as the map data set means that the data= data set has a record for every boundary point in the map data. You only need one record for each value of your choro and id variable(s) with the values to apply to the map.

 

 

Your data= data set needs to have a character variable with the text you want to display for the "point" though a region works better. Then in the CHORO statement add the option HTML=thatvariablename

rcleven2
Obsidian | Level 7

 

As it stands right now, I have removed the warnings. I found that there was something going on with my annotate data sets that was duplicating lines. So a Stat=first options took care of that. MY problem still remains that the html=thatvaribalename is still not providing me with the hover over effect. I am thinking it has to be in ODS statement or an option outside of the proc gmap procedure. Here is how the very end of my code looks now. What else might I do to get the right output?

 

 


goptions reset=all device=png;
ods html path="c:\users\rgclevenger\desktop\Maps" (url=none) file="hiv_map.html"   ;
 

	proc gmap data=data map=districtmap all anno=annotate_dots ;
		id state county;
		choro state / nolegend html=name stat=first;
		pattern1 v=s c=cornflowerblue;	
	run;

proc gmap data=district_data map=districtmap all anno=annotate_district_dots ; id state county; choro state / nolegend anno=anno_legend html=Name stat=first; pattern1 v=s c=lig; run; ods html close; ods listing;

 

ballardw
Super User

Without data it is hard to say but I suspect you didn't look into the requirements for the html variable appearance. The text needs to be in a specific appearance to tell the HTML viewer how to use the item. Example:

data displaydata;
   set mapsgfk.us_states;
   by notsorted statecode;
   if first.statecode;
   statename= cats('title=',quote(stnamel(statecode)));
   value= 100*rand('uniform');
   
   keep  statecode statename value;
run;


proc gmap data=displaydata all map=mapsgfk.us_states;
   id statecode;
   choro value/html=statename
               nolegend;
run;
quit;

The text to appear wants the value to appear as Title="actual text to display" in the variable referenced by the HTML option.

 

rcleven2
Obsidian | Level 7

Ok, so we are making progress. The one bit of code I was not using was the title=. That was my first problem. But now what is happening is that I only have six counties that I am mapping with about 260 dots on my map. When I hover over a dot, each dot says the same thing in each county. So every dot in County A will have Bob and every dot in county B will have Claire. I have my response dataset organized by county then name of the patient. The first patient in each county is the one that is showing up when I hover over any dot within that county. I thought maybe the problem was that names were being retained in the dataset but that is not the case. Each observation has a different hover_variable name. 

 

So what am I missing now?

GraphGuy
Meteorite | Level 14

Sounds like you want hover-over text for each annotated dot, rather than the map polygon areas/states (?)...

 

Therefore you'll want to get rid of the html=statename in the Proc Gmap (this was what produced 1 hover-over text for each state), and you'll want to add a variable called 'html' in the annotate dataset, with the information you want in the hover-over text for each annotated dot. Something like ...

 

data annotate_dots; set annotate_dots;

length html $300;

html='title='||quote(trim(left(name)));

run;

 

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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