Graphics Programming

Data visualization using SAS programming, including ODS Graphics and SAS/GRAPH. Charts, plots, maps, and more!
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
rcleven2
Obsidian | Level 7

I have posted on here before about adding Hover-Over tooltip text and I have been successful with the help of the community at adding it to my output. However, I have completed a new project and now for some reason I can not get the too-tip text to pop up. Attached if the graphic output that I get from my code. The hover text should appear over and identify the roadways. I have compared the current code i have for this project to other code i have done for completely different projects that still provide me with the desired outcome and I can not tell what I have done wrong. 

I have tried inserting the Var= "title='" !!  !! "'" statement in at different points and different data sets. 

I have a Boundary map data set, the road annotat dataset and the plotted points dataset. I just want the name of the roads (Variable "FULLNAME") to appear at hover test. 

 

Please help

 

/* MAP DATASET */
data cherokee_county_map;
	set map;
	where county =57;
run;
/* ROAD DATASET */
proc sort data=work.road;
	by linearid;
run;

%annomac()
data cherokee_map_roads;
	%dclanno
	set road;
	by linearid;
	html="title='" !! trim(left(fullname)) !! "'";
	%system(2,2,3)
	when='A';
	if first.linearid then function='MOVE';
		else function='DRAW';
	color='antiquewhite';
	size=.01;
	if rttyp='I' then
		do;
			color='crimson';
			size = .4;
		
		end;
	if rttyp='S' then 
		do;
			color='gold';
			size=.2;
		
		end;
run;
proc sort data=cherokee_map_roads;
	by size;
run;

/* DATA/Annotate DATASET */
data data1;
	set data;
	if county ne 57 then delete;
run; 
data annotate_district_dots(keep=x y state statecode county _status_ patient_id event_id sex race ethnicity dx collect_dt when text color style size xsys ysys hsys);
			%dclanno
			length text $60;
			set data1;
		/*	LABEL(x1, y1, text, color, ang, rot, ht, font, pos)*/
			%system(2,2,1);
			when='a';
			
			if sex = 1 then point='Q';
				else if sex = 2 then point="R";
			if dx='bad' then color='papb';
				else if dx='sucks' then color='ligb';
				else if dx='the worst' then color='coral';
				else color='mediumvioletred';
		%label(x,y,point,*,0,0,2,'Marker',5);
run;


data all_dxs;
	set work.annotate_district_dots;
	
run;


data annotations;
	set work.cherokee_map_roads work.all_dxs;
	html="title='" !! (trim(left(fullname))) !! "'";
run;



goptions reset=all device=png;
/*ods pdf file="c:\users\rgclevenger\desktop\SASoutput\Maps\tif_dot.pdf";*/
ods html path="c:\users\rgclevenger\desktop\SASoutput\Maps" (url=none) file="Tiffany_TO.html";

title "MAP OF CHEROKEE COUNTY";
title2 "Geo-Locating of all STD's in 2017";
proc gmap data=work.annotations map=cherokee_county_map all anno=work.annotations ;
	id state county;
	choro state /
					nolegend 
					stat=first 
					cempty=darkgray 
					woutline=1
					
					;	
	pattern1 v=s c=darkseagreen;
run;

ods _all_ close;
goptions reset=all;

 

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

I did a few tests and annotate does not create the tooltip for lines.

 

I wrote a macro that does it for you. I started playing with line tip styles, but can't really spend more time on this.

 


%macro lineplus(x1, y1, x2, y2, width, fillcolor, fillpattern, edgecolor, edgestyle, edgesize, tipstyle);
  %if ^%length(&width      ) %then %let width      = 1    ;
  %if ^%length(&fillcolor  ) %then %let fillcolor  = black;
  %if ^%length(&fillpattern) %then %let fillpattern= ms   ;
  %if ^%length(&edgecolor  ) %then %let edgecolor  = red  ;
  %if ^%length(&edgestyle  ) %then %let edgestyle  = 1    ;
  %if ^%length(&edgesize   ) %then %let edgesize   = 1    ;

  %local angle;
  %let angle=%sysfunc( atan2(&y2-&y1,&x2-&x1) ); 

  X = &x2.-sin(&angle.)*&width.; 
  Y = &y2.+cos(&angle.)*&width.;
  %poly2(X, Y, &fillcolor., &fillpattern., &edgestyle., &edgesize.);
  X = &x2.+sin(&angle.)*&width.; 
  Y = &y2.-cos(&angle.)*&width.;
  %polycont(X, Y, &edgecolor.);
  X = &x1.+sin(&angle.)*&width.; 
  Y = &y1.-cos(&angle.)*&width.;
  %polycont(X, Y, &edgecolor.);
  X = &x1.-sin(&angle.)*&width.; 
  Y = &y1.+cos(&angle.)*&width.;
  %polycont(X, Y, &edgecolor.);

  %if &tipstyle.=round %then 
  %slice(&x1., &y1., 0, 360, &width./2, &fillcolor., &fillpattern., 0);

%mend;        
  
data ANNO;  
  retain XSYS YSYS '1' HTML 'title="aa"';
  %lineplus(30, 30, 40, 40, 1); 
  %lineplus(10, 10, 20, 10, 1, green, ms, green, 1, 0, round);
run;  
 
goptions xpixels=500 ypixels=500;
proc ganno annotate =ANNO; 
run;

 

Capture.PNG

 

View solution in original post

8 REPLIES 8
ballardw
Super User

It looks like your are missing the HTML= option on the CHORO statement to indicate the variable with the text to display.

rcleven2
Obsidian | Level 7

There most definitely is a variable in the Annotations DS named HTML and an example of what one observation may hold would be title='Bluffs Pkwy'. If I put html=html in the Choro statement nothing happens. No error, No warning, no text. I have played around with naming it something different and even specifying the dataset that hold that variable in different positions whether it be the data= , map= or anno=. None of it works. 

 

Here is a protion of the code form a totally separate program that still works. The difference is in the one that works I have the text hover over plotted points at to here I want it to hover over the streets.


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


/*ROADS* - Only need the roads that are located within the square window of the district */
data lat_long_road;
	set work.road;
	where x between -0.027927437 and -0.012479502 and y between 0.0244506075 and 0.0405140664;
run;
	proc sort data=work.districtmap ;
		by state county;
	run;
			/* Procedure that trims all roads that are not INSIDE the map area */
			proc ginside data=lat_long_road map=work.districtmap insideonly out=Georgia_roads;
				id state county;
			run;

%annomac()
					data district_roads;
						%dclanno
						set work.georgia_roads;
						by linearid;
						%system(2,2,3);
						when = 'b';
						if first.linearid then function='MOVE';
							else function='DRAW';
						if mtfcc='S1100' then do;
									color='tomato';
									size=.4;
								end;
							else if mtfcc='S1200' then do;
									color='lightseagreen';
									size=.1;
								end;
					run;

/* PATIENT DOTS*/
data district_data;
	set data;
	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 point='L' then output;	
run;

		data annotate_district_dots(keep=x y state statecode county _status_ urn patient_name patient_type html when text color style size xsys ysys hsys);
			%dclanno
			length text $60;
			length state_fips 5;
			set district_data;
			html="title='" !! trim(left(patient_name)) !! "'"; 
			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='goldenrod';
				else if patient_type="3" then color='dodgerblue';
			%label(x,y,point,*,0,0,3.5,'Special',5);
			output;
		run;
		data anno_size;
			set work.annotate_district_dots;
			if color='dodgerblue' then size=3;
			output;	
		run;	
			proc sort data=anno_size out=anno_nodup nodupkey;
				by urn;
			run;
				proc sort data=anno_nodup out=annotate_pt_loc ;
					by descending patient_type;
				run;

/*ROADS  +  DOTS*/;
data anna_tate;
	set annotate_pt_loc district_roads;
run;

/*Legend to show on map*/
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',goldenrod,0,0,6,'Special',5);
	%label(5,10,'New to TLBC',black,0,0,4,'Thorndale AMT',6);
	%label(3,5,'J',dodgerblue,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\SASoutput\Maps" (url=none) file="map.html";

proc gmap data=district_data map=districtmap all anno=anna_tate ;
	id state county;
	choro state /  nolegend 
					anno=anno_legend 
					stat=first 
					cempty=darkgray 
					woutline=1
					;	
	pattern1 v=s c=A90D9D733;
run;

ods _all_ close;
goptions reset=all;
rcleven2
Obsidian | Level 7

Also I believe that the HTML= option in the choro statement is to specify tooltip text over boundary areas and not plotted points. I remember that was one hang up the first time around i was trying to plot annotated points with hover text. 

ChrisNZ
Tourmaline | Level 20

 

I can't spot anything odd in your program, but it's difficult to reply without running any code.

I would:

1- Post a bit of data so we can run your code.

2- Look in the HTML page for any malformed HTML tag.

rcleven2
Obsidian | Level 7
goptions reset=all device=png;

ods html path="c:\users\rgclevenger\desktop\SASoutput\Maps" (url=none) file="road_hover.html";

title "Map of Health Departments in Cherokee Co.";
title2 "with Hover Text for Roads";
proc gmap data=sascom.data map=sascom.cherokee_county_map all anno=sascom.annotate_cherokee_map_roads ;
	id state county;
	choro state /	anno=sascom.annotate_data	
					html= "?"
					nolegend 
					stat=first 
					cempty=darkgray 
					woutline=1
					
					;	
	pattern1 v=s c=darkseagreen;
run;

ods _all_ close;
goptions reset=all;

The code for Proc Gmap that I have been using and all the necessary data file. 

  • The same Map Dataset
  • The same Road dataset with annotations <This is where the tooltip text should come from, Variable "FULLNAME">
  • Sample Data
  • Sample Data with Annotations
rcleven2
Obsidian | Level 7

Data sets in Excel format. I can not get them to upload as sas dataset files. 

ChrisNZ
Tourmaline | Level 20

I did a few tests and annotate does not create the tooltip for lines.

 

I wrote a macro that does it for you. I started playing with line tip styles, but can't really spend more time on this.

 


%macro lineplus(x1, y1, x2, y2, width, fillcolor, fillpattern, edgecolor, edgestyle, edgesize, tipstyle);
  %if ^%length(&width      ) %then %let width      = 1    ;
  %if ^%length(&fillcolor  ) %then %let fillcolor  = black;
  %if ^%length(&fillpattern) %then %let fillpattern= ms   ;
  %if ^%length(&edgecolor  ) %then %let edgecolor  = red  ;
  %if ^%length(&edgestyle  ) %then %let edgestyle  = 1    ;
  %if ^%length(&edgesize   ) %then %let edgesize   = 1    ;

  %local angle;
  %let angle=%sysfunc( atan2(&y2-&y1,&x2-&x1) ); 

  X = &x2.-sin(&angle.)*&width.; 
  Y = &y2.+cos(&angle.)*&width.;
  %poly2(X, Y, &fillcolor., &fillpattern., &edgestyle., &edgesize.);
  X = &x2.+sin(&angle.)*&width.; 
  Y = &y2.-cos(&angle.)*&width.;
  %polycont(X, Y, &edgecolor.);
  X = &x1.+sin(&angle.)*&width.; 
  Y = &y1.-cos(&angle.)*&width.;
  %polycont(X, Y, &edgecolor.);
  X = &x1.-sin(&angle.)*&width.; 
  Y = &y1.+cos(&angle.)*&width.;
  %polycont(X, Y, &edgecolor.);

  %if &tipstyle.=round %then 
  %slice(&x1., &y1., 0, 360, &width./2, &fillcolor., &fillpattern., 0);

%mend;        
  
data ANNO;  
  retain XSYS YSYS '1' HTML 'title="aa"';
  %lineplus(30, 30, 40, 40, 1); 
  %lineplus(10, 10, 20, 10, 1, green, ms, green, 1, 0, round);
run;  
 
goptions xpixels=500 ypixels=500;
proc ganno annotate =ANNO; 
run;

 

Capture.PNG

 

rcleven2
Obsidian | Level 7

I appreciate it. I may have to find a different solution to the problem but this is definitely helpful. Im glad I know now that lines are the problem and not something I was doing in the code.  

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 8 replies
  • 3671 views
  • 1 like
  • 3 in conversation