Data visualization with SAS programming

Really Need Assistance With Moving a Map Label in SAS EG 6.1.

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 7
Accepted Solution

Really Need Assistance With Moving a Map Label in SAS EG 6.1.

Hello I received help on this topic a while ago and my map is almost there. The issue is that i cannot move the hospital number on the map. I've tried everything under the sun, but I just cannot get the number moved for the counties where the label does not quite go in the middle. Take Erie county for instance. I am able to reposition Erie, but cannot move the 1. I'm hopping i am making some sense here. I'm also hoping there is someone who can help me move this darn number. I have attached the code with the output. Thank you everyone.

 

1                                                          The SAS System                              11:29 Wednesday, May 24, 2017

1          ;*';*";*/;quit;run;
2          OPTIONS PAGENO=MIN;
3          %LET _CLIENTTASKLABEL='Program';
4          %LET _CLIENTPROJECTPATH='';
5          %LET _CLIENTPROJECTNAME='';
6          %LET _SASPROGRAMFILE=;
7          
8          ODS _ALL_ CLOSE;
9          OPTIONS DEV=ACTIVEX;
10         GOPTIONS XPIXELS=0 YPIXELS=0;
11         FILENAME EGSR TEMP;
12         ODS tagsets.sasreport13(ID=EGSR) FILE=EGSR
13             STYLE=HtmlBlue
14             STYLESHEET=(URL="file:///C:/Program%20Files/SASHome/SASEnterpriseGuide/6.1/Styles/HtmlBlue.css")
15             NOGTITLE
16             NOGFOOTNOTE
17             GPATH=&sasworklocation
18             ENCODING=UTF8
19             options(rolap="on")
20         ;
NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR
21         
22         GOPTIONS ACCESSIBLE;
23         proc gproject data=maps.counties out=ohio;
24         
25         /* State FIPS for Ohio */
26         
27         where state=39;
28         
29         id state county;
30         
31         run;

NOTE: PARALLEL1 = 39.296591805.
NOTE: PARALLEL2 = 41.084789971.
NOTE: MERIDIAN = 82.669167298.
NOTE: There were 4247 observations read from the data set MAPS.COUNTIES.
      WHERE state=39;
NOTE: The data set WORK.OHIO has 4247 observations and 6 variables.
NOTE: Compressing data set WORK.OHIO increased size by 150.00 percent. 
      Compressed is 5 pages; un-compressed would require 2 pages.
NOTE: PROCEDURE GPROJECT used (Total process time):
      real time           0.05 seconds
      cpu time            0.05 seconds
      

32         
33         quit;
34         proc sort data=mapsgfk.us_counties out=centroids;
35           by state county segment;
36         run;

NOTE: There were 1379662 observations read from the data set MAPSGFK.US_COUNTIES.
NOTE: The data set WORK.CENTROIDS has 1379662 observations and 13 variables.
NOTE: Compressing data set WORK.CENTROIDS increased size by 1.48 percent. 
      Compressed is 2056 pages; un-compressed would require 2026 pages.
NOTE: PROCEDURE SORT used (Total process time):
      real time           1.81 seconds
2                                                          The SAS System                              11:29 Wednesday, May 24, 2017

      cpu time            1.84 seconds
      

37         data centroids_temp;
38           retain yi yj xi xj a cx cy x0 y0 0;
39           set centroids(keep=state county segment lat long rename=(lat=yj long=xj));
40           by state county segment;
41           if(first.segment) then do;
42             cx = 0;
43             cy = 0;
44             a = 0;
45             x0 = xj;
46             y0 = yj;
47           end;
48           else if(not first.segment) then do;
49             ta = (xi*yj - xj*yi);
50             cx + ((xi+xj)*ta);
51             cy + ((yi+yj)*ta);
52             a + ta;
53           end;
54           if(last.segment) then do;
55             ta = (xj*y0 - x0*yj);
56             cx + ((xj+x0)*ta);
57             cy + ((yj+y0)*ta);
58             a  = ta + a * 0.5;
59             cx = cx / (6*a);
60             cy = cy / (6*a);
61             output;
62           end;
63           xi = xj;
64           yi = yj;
65         run;

NOTE: Division by zero detected at line 59 column 13.
NOTE: Division by zero detected at line 60 column 13.
yi=40.623819 yj=40.623819 xi=-73.424268 xj=-73.424268 a=0 cx=. cy=. x0=-73.424268 y0=40.623819 STATE=36 COUNTY=59 SEGMENT=170
FIRST.STATE=0 LAST.STATE=0 FIRST.COUNTY=0 LAST.COUNTY=1 FIRST.SEGMENT=0 LAST.SEGMENT=1 ta=0 _ERROR_=1 _N_=961421
NOTE: Division by zero detected at line 59 column 13.
NOTE: Division by zero detected at line 60 column 13.
yi=36.227656 yj=36.227656 xi=-75.79265 xj=-75.79265 a=0 cx=. cy=. x0=-75.79265 y0=36.227656 STATE=37 COUNTY=53 SEGMENT=112
FIRST.STATE=0 LAST.STATE=0 FIRST.COUNTY=0 LAST.COUNTY=1 FIRST.SEGMENT=0 LAST.SEGMENT=1 ta=0 _ERROR_=1 _N_=995393
NOTE: Missing values were generated as a result of performing an operation on missing values.
      Each place is given by: (Number of times) at (Line):(Column).
      76 at 49:13   76 at 50:14   76 at 51:14   
NOTE: Mathematical operations could not be performed at the following places. The results of the operations have been set to 
      missing values.
      Each place is given by: (Number of times) at (Line):(Column).
      2 at 59:13   2 at 60:13   
NOTE: There were 1379662 observations read from the data set WORK.CENTROIDS.
NOTE: The data set WORK.CENTROIDS_TEMP has 27310 observations and 13 variables.
NOTE: Compressing data set WORK.CENTROIDS_TEMP increased size by 14.63 percent. 
      Compressed is 47 pages; un-compressed would require 41 pages.
NOTE: DATA statement used (Total process time):
      real time           0.54 seconds
      cpu time            0.52 seconds
      

66         proc sql;
3                                                          The SAS System                              11:29 Wednesday, May 24, 2017

67           create table centroid_weight as
68           select
69             state, county, sum(a) as sum
70           from centroids_temp
71             group by state, county;
NOTE: Compression was disabled for data set WORK.CENTROID_WEIGHT because compression overhead would increase the size of the data 
      set.
NOTE: Table WORK.CENTROID_WEIGHT created, with 3143 rows and 3 columns.

72         quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.05 seconds
      cpu time            0.04 seconds
      

73         proc sql;
74           create table centroids as
75           select a.state, a.county,
76                  sum(cx*(a / sum)) as lat,
77                  sum(cy*(a / sum)) as long
78             from centroids_temp a
79             inner join centroid_weight b
80               on (a.state = b.state and a.county = b.county)
81             group by a.state, a.county;
NOTE: Compressing data set WORK.CENTROIDS increased size by 100.00 percent. 
      Compressed is 4 pages; un-compressed would require 2 pages.
NOTE: Table WORK.CENTROIDS created, with 3143 rows and 4 columns.

82         quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.08 seconds
      cpu time            0.09 seconds
      

83         proc sql;
84           drop table centroids_temp;
NOTE: Table WORK.CENTROIDS_TEMP has been dropped.
85           drop table centroid_weight;
NOTE: Table WORK.CENTROID_WEIGHT has been dropped.
86         quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

87         PROC SQL;
88            CREATE TABLE WORK.FILTER_FOR_CENTROIDS AS
89            SELECT t1.STATE,
90                   t1.COUNTY,
91                   t1.lat,
92                   t1.long
93               FROM WORK.CENTROIDS t1
94               WHERE t1.STATE = 39;
NOTE: Compressing data set WORK.FILTER_FOR_CENTROIDS increased size by 100.00 percent. 
      Compressed is 2 pages; un-compressed would require 1 pages.
NOTE: Table WORK.FILTER_FOR_CENTROIDS created, with 88 rows and 4 columns.

95         QUIT;
4                                                          The SAS System                              11:29 Wednesday, May 24, 2017

NOTE: PROCEDURE SQL used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
      

96         
97         proc format library=work;
98          value ohiohos_
99          1 = '1'
100         2 = '2'
101         3 - 5 = '3 - 5'
102         6 - 7 = '6 - 7'
103         7 - 21 = '7 or more'
104         ;
NOTE: Format OHIOHOS_ is already on the library WORK.FORMATS.
NOTE: Format OHIOHOS_ has been output.
105        run;

NOTE: PROCEDURE FORMAT used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds
      

106        data work.numofhos0;
107        input county ohiohos @@;
108        HospText = put(ohiohos,ohiohos_.);
109        datalines;

NOTE: SAS went to a new line when INPUT statement reached past the end of a line.
NOTE: The data set WORK.NUMOFHOS0 has 88 observations and 3 variables.
NOTE: Compressing data set WORK.NUMOFHOS0 increased size by 100.00 percent. 
      Compressed is 2 pages; un-compressed would require 1 pages.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds
      
132        ;

133        run;
134        
135        proc sql;
136           create table work.ohnames as
137           select distinct county, countynm label='County Name'
138           from sashelp.zipcode
139           where state=39;
NOTE: Compressing data set WORK.OHNAMES increased size by 100.00 percent. 
      Compressed is 2 pages; un-compressed would require 1 pages.
NOTE: Table WORK.OHNAMES created, with 88 rows and 2 columns.

140        quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.03 seconds
      cpu time            0.02 seconds
      

141        %annomac;
 
*** ANNOTATE macros are now available ***
5                                                          The SAS System                              11:29 Wednesday, May 24, 2017

 
 For further information on ANNOTATE macros, enter,
    %HELPANO(macroname), (for specific macros)
    %HELPANO(ALL), (for information on all macros)
 or %HELPANO (for a list of macro names)
 
142        %maplabel(work.ohio,work.ohnames,work.nameanno,countynm, county,font='Albany AMT/''boldt',
143                  color=black,size=1.5);

NOTE: There were 1 observations read from the data set WORK.OHIO.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      


NOTE: There were 4247 observations read from the data set WORK.OHIO.
NOTE: The data set WORK.DATA109 has 4247 observations and 6 variables.
NOTE: Compressing data set WORK.DATA109 increased size by 150.00 percent. 
      Compressed is 5 pages; un-compressed would require 2 pages.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
      


NOTE: There were 4247 observations read from the data set WORK.DATA109.
NOTE: The data set WORK.NAMEANNO has 88 observations and 8 variables.
NOTE: Compressing data set WORK.NAMEANNO increased size by 100.00 percent. 
      Compressed is 2 pages; un-compressed would require 1 pages.
NOTE: PROCEDURE SUMMARY used (Total process time):
      real time           0.01 seconds
      cpu time            0.02 seconds
      


NOTE: There were 88 observations read from the data set WORK.NAMEANNO.
NOTE: The data set WORK.NAMEANNO has 88 observations and 4 variables.
NOTE: Compressing data set WORK.NAMEANNO increased size by 100.00 percent. 
      Compressed is 2 pages; un-compressed would require 1 pages.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds
      


NOTE: Compression was disabled for data set WORK.DATA109 because compression overhead would increase the size of the data set.
NOTE: There were 88 observations read from the data set WORK.NAMEANNO.
NOTE: There were 4247 observations read from the data set WORK.DATA109.
NOTE: The data set WORK.DATA109 has 184 observations and 3 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
      


NOTE: There were 184 observations read from the data set WORK.DATA109.
NOTE: The data set WORK.DATA109 has 184 observations and 3 variables.
6                                                          The SAS System                              11:29 Wednesday, May 24, 2017

NOTE: PROCEDURE SORT used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds
      


NOTE: Compression was disabled for data set WORK.NAMEANNO because compression overhead would increase the size of the data set.
NOTE: There were 184 observations read from the data set WORK.DATA109.
NOTE: The data set WORK.NAMEANNO has 88 observations and 3 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
      


NOTE: There were 88 observations read from the data set WORK.OHNAMES.
NOTE: The data set WORK.DATA110 has 88 observations and 2 variables.
NOTE: Compressing data set WORK.DATA110 increased size by 100.00 percent. 
      Compressed is 2 pages; un-compressed would require 1 pages.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
      


NOTE: There were 88 observations read from the data set WORK.DATA110.
NOTE: The data set WORK.DATA110 has 88 observations and 2 variables.
NOTE: Compressing data set WORK.DATA110 increased size by 100.00 percent. 
      Compressed is 2 pages; un-compressed would require 1 pages.
NOTE: PROCEDURE SORT used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
      


NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
      143:148   
WARNING: Multiple lengths were specified for the BY variable COUNTY by input data sets. This might cause unexpected results.
NOTE: There were 88 observations read from the data set WORK.NAMEANNO.
NOTE: There were 88 observations read from the data set WORK.DATA110.
NOTE: The data set WORK.NAMEANNO has 88 observations and 14 variables.
NOTE: Compressing data set WORK.NAMEANNO increased size by 100.00 percent. 
      Compressed is 2 pages; un-compressed would require 1 pages.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds
      


NOTE: There were 88 observations read from the data set WORK.NAMEANNO.
NOTE: 0 observations with duplicate key values were deleted.
NOTE: The data set WORK.NAMEANNO has 88 observations and 14 variables.
NOTE: Compressing data set WORK.NAMEANNO increased size by 100.00 percent. 
      Compressed is 2 pages; un-compressed would require 1 pages.
NOTE: PROCEDURE SORT used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
      
7                                                          The SAS System                              11:29 Wednesday, May 24, 2017


144        %maplabel(work.ohio,work.numofhos0,work.Hospanno,ohiohos, county,font='Albany AMT/''boldt',
145                  color=black,size=1.7);

NOTE: There were 1 observations read from the data set WORK.OHIO.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      


NOTE: There were 4247 observations read from the data set WORK.OHIO.
NOTE: The data set WORK.DATA111 has 4247 observations and 6 variables.
NOTE: Compressing data set WORK.DATA111 increased size by 150.00 percent. 
      Compressed is 5 pages; un-compressed would require 2 pages.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
      


NOTE: There were 4247 observations read from the data set WORK.DATA111.
NOTE: The data set WORK.HOSPANNO has 88 observations and 8 variables.
NOTE: Compressing data set WORK.HOSPANNO increased size by 100.00 percent. 
      Compressed is 2 pages; un-compressed would require 1 pages.
NOTE: PROCEDURE SUMMARY used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
      


NOTE: There were 88 observations read from the data set WORK.HOSPANNO.
NOTE: The data set WORK.HOSPANNO has 88 observations and 4 variables.
NOTE: Compressing data set WORK.HOSPANNO increased size by 100.00 percent. 
      Compressed is 2 pages; un-compressed would require 1 pages.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
      


NOTE: Compression was disabled for data set WORK.DATA111 because compression overhead would increase the size of the data set.
NOTE: There were 88 observations read from the data set WORK.HOSPANNO.
NOTE: There were 4247 observations read from the data set WORK.DATA111.
NOTE: The data set WORK.DATA111 has 184 observations and 3 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
      


NOTE: There were 184 observations read from the data set WORK.DATA111.
NOTE: The data set WORK.DATA111 has 184 observations and 3 variables.
NOTE: PROCEDURE SORT used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds
      

8                                                          The SAS System                              11:29 Wednesday, May 24, 2017


NOTE: Compression was disabled for data set WORK.HOSPANNO because compression overhead would increase the size of the data set.
NOTE: There were 184 observations read from the data set WORK.DATA111.
NOTE: The data set WORK.HOSPANNO has 88 observations and 3 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
      


NOTE: There were 88 observations read from the data set WORK.NUMOFHOS0.
NOTE: The data set WORK.DATA112 has 88 observations and 3 variables.
NOTE: Compressing data set WORK.DATA112 increased size by 100.00 percent. 
      Compressed is 2 pages; un-compressed would require 1 pages.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds
      


NOTE: There were 88 observations read from the data set WORK.DATA112.
NOTE: The data set WORK.DATA112 has 88 observations and 3 variables.
NOTE: Compressing data set WORK.DATA112 increased size by 100.00 percent. 
      Compressed is 2 pages; un-compressed would require 1 pages.
NOTE: PROCEDURE SORT used (Total process time):
      real time           0.02 seconds
      cpu time            0.01 seconds
      


NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
      145:148   145:1     145:1     
WARNING: Multiple lengths were specified for the BY variable COUNTY by input data sets. This might cause unexpected results.
NOTE: There were 88 observations read from the data set WORK.HOSPANNO.
NOTE: There were 88 observations read from the data set WORK.DATA112.
NOTE: The data set WORK.HOSPANNO has 88 observations and 14 variables.
NOTE: Compressing data set WORK.HOSPANNO increased size by 100.00 percent. 
      Compressed is 2 pages; un-compressed would require 1 pages.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds
      


NOTE: There were 88 observations read from the data set WORK.HOSPANNO.
NOTE: 0 observations with duplicate key values were deleted.
NOTE: The data set WORK.HOSPANNO has 88 observations and 14 variables.
NOTE: Compressing data set WORK.HOSPANNO increased size by 100.00 percent. 
      Compressed is 2 pages; un-compressed would require 1 pages.
NOTE: PROCEDURE SORT used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds
      

146        
147        data work.combinedanno ;
148        	
149           set
9                                                          The SAS System                              11:29 Wednesday, May 24, 2017

150            work.nameanno (in=Name)
151        	work.Hospanno (in=Hosp)
152        	;
153        if Name then position = '2';
154        
155        Else if Hosp then position = '5';
156        if county=43 then position = '9';
157        if county=143 then position = 'E';
158        
159           /* this is where you could put if statements to adjust
160              the x and or y coordinates to display name or value
161           */
162        
163        run;

NOTE: There were 88 observations read from the data set WORK.NAMEANNO.
NOTE: There were 88 observations read from the data set WORK.HOSPANNO.
NOTE: The data set WORK.COMBINEDANNO has 176 observations and 15 variables.
NOTE: Compressing data set WORK.COMBINEDANNO increased size by 100.00 percent. 
      Compressed is 2 pages; un-compressed would require 1 pages.
NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      cpu time            0.01 seconds
      

164        title1 "Map of Ohio Hospitals By County";
165        
166         /* Generate a county map of Ohio with county labels */
167        
168        pattern1 v=s color=azure;
169        pattern2 v=s c=cyan;
170        pattern3 v=s color=ligr;
171        pattern4 v=s color=bisque;
172        pattern5 v=s c=bibg;
173        pattern6 v=s color=lime;
174        
175        
176        proc gmap data=work.numofhos0 map=work.ohio;
177           id  county;
178           choro ohiohos / anno=work.combinedanno
179                           discrete
180                           coutline=black;
181           format ohiohos ohiohos_.;
182           label ohiohos= "Number of Hospitals";
183        run;

184        quit;

NOTE: There were 176 observations read from the data set WORK.COMBINEDANNO.
NOTE: PROCEDURE GMAP used (Total process time):
      real time           0.09 seconds
      cpu time            0.06 seconds
      
184      !       title;

185        
186        
187        
10                                                         The SAS System                              11:29 Wednesday, May 24, 2017

188        GOPTIONS NOACCESSIBLE;
189        %LET _CLIENTTASKLABEL=;
190        %LET _CLIENTPROJECTPATH=;
191        %LET _CLIENTPROJECTNAME=;
192        %LET _SASPROGRAMFILE=;
193        
194        ;*';*";*/;quit;run;
195        ODS _ALL_ CLOSE;
196        
197        
198        QUIT; RUN;
199        

Thanks in advance

 

proc gproject data=maps.counties out=ohio;

/* State FIPS for Ohio */

where state=39;

id state county;

run;

quit;
proc sort data=mapsgfk.us_counties out=centroids;
  by state county segment;
run;
data centroids_temp;
  retain yi yj xi xj a cx cy x0 y0 0;
  set centroids(keep=state county segment lat long rename=(lat=yj long=xj));
  by state county segment;
  if(first.segment) then do;
    cx = 0;
    cy = 0;
    a = 0;
    x0 = xj;
    y0 = yj;
  end;
  else if(not first.segment) then do;
    ta = (xi*yj - xj*yi);
    cx + ((xi+xj)*ta);
    cy + ((yi+yj)*ta);
    a + ta;
  end;
  if(last.segment) then do;
    ta = (xj*y0 - x0*yj);
    cx + ((xj+x0)*ta);
    cy + ((yj+y0)*ta);
    a  = ta + a * 0.5;
    cx = cx / (6*a);
    cy = cy / (6*a);
    output;
  end;
  xi = xj;
  yi = yj;
run;
proc sql;
  create table centroid_weight as
  select
    state, county, sum(a) as sum
  from centroids_temp
    group by state, county;
quit;
proc sql;
  create table centroids as
  select a.state, a.county,
         sum(cx*(a / sum)) as lat,
         sum(cy*(a / sum)) as long
    from centroids_temp a
    inner join centroid_weight b
      on (a.state = b.state and a.county = b.county)
    group by a.state, a.county;
quit;
proc sql;
  drop table centroids_temp;
  drop table centroid_weight;
quit;
PROC SQL;
   CREATE TABLE WORK.FILTER_FOR_CENTROIDS AS 
   SELECT t1.STATE, 
          t1.COUNTY, 
          t1.lat, 
          t1.long
      FROM WORK.CENTROIDS t1
      WHERE t1.STATE = 39;
QUIT;

proc format library=work;
 value ohiohos_
 1 = '1'
 2 = '2'
 3 - 5 = '3 - 5'
 6 - 7 = '6 - 7'
 7 - 21 = '7 or more'
 ;
run;
data work.numofhos0;
input county ohiohos @@;
HospText = put(ohiohos,ohiohos_.);
datalines;
001 1 003 5 005 1 007 3
009 2 011 1 013 3 015 0
017 5 019 0 021 1 023 3
025 1 027 1 029 2 031 1
033 2 035 21 037 1 039 3
041 1 043 1 045 2 047 1
049 17 051 1 053 1 055 2
057 2 059 2 061 16 063 2
065 1 067 1 069 1 071 2
073 1 075 1 077 2 079 1
081 3 083 1 085 2 087 1
089 1 091 1 093 5 095 13
097 1 099 7 101 1 103 2
105 0 107 1 109 1 111 0
113 12 115 0 117 1 119 2
121 0 123 1 125 1 127 0
129 1 131 1 133 1 135 0
137 0 139 3 141 1 143 3
145 2 147 1 149 1 151 6
153 12 155 4 157 3 159 1
161 2 163 0 165 1 167 2
169 2 171 2 173 1 175 1
;
run;

proc sql;
   create table work.ohnames as
   select distinct county, countynm label='County Name'
   from sashelp.zipcode
   where state=39;
quit;
%annomac;
%maplabel(work.ohio,work.ohnames,work.nameanno,countynm, county,font='Albany AMT/''boldt',
          color=black,size=1.5);
%maplabel(work.ohio,work.numofhos0,work.Hospanno,ohiohos, county,font='Albany AMT/''boldt',
          color=black,size=1.7);

data work.combinedanno;
   set 
      work.nameanno (in=Name)
	work.Hospanno (in=Hosp) ;
   if Name then position = '2';

   Else if Hosp then position = '5';
  	if county=123 then position = 'F';
	if county=43 then position = '9';
	if county=143 then position = 'E';

   /* this is where you could put if statements to adjust
      the x and or y coordinates to display name or value
   */
run;
title1 "Map of Ohio Hospitals By County";

 /* Generate a county map of Ohio with county labels */

pattern1 v=s color=azure;
pattern2 v=s c=cyan;
pattern3 v=s color=ligr;
pattern4 v=s color=bisque;
pattern5 v=s c=bibg;
pattern6 v=s color=lime;


proc gmap data=work.numofhos0 map=work.ohio;
   id  county;
   choro ohiohos / anno=work.combinedanno 
                   discrete 
                   coutline=black;
   format ohiohos ohiohos_.;
   label ohiohos= "Number of Hospitals"; 
run;
quit; 

 

 

Attachment

Accepted Solutions
Solution
‎05-25-2017 09:48 AM
Grand Advisor
Posts: 10,050

Re: Really Need Assistance With Moving a Map Label in SAS EG 6.1.

Most of the code you posted is not needed. The key bit will be in this data step:

data work.combinedanno;
   set 
      work.nameanno (in=Name)
	work.Hospanno (in=Hosp) ;
   if Name then position = '2';

   Else if Hosp then position = '5';
  	if county=123 then position = 'F';
	if county=43 then position = '9';
	if county=143 then position = 'E';

   /* this is where you could put if statements to adjust
      the x and or y coordinates to display name or value
   */
run;

You will need to examine the coordinate from you map of the counties or hospitals that you do not like.

 

Then look them up in the above data set. You then conditional change either the x, the y or both coordinates.

Suppose County x label has a coordinate of x= -0.027 and y= -0.035 (which since the center of the map is usually (0,0) ) and I want to move that label a little bit to the left (negative) and up (positive) I would add something like:

If County = xxx then do;

   x= -0.033; ( or use x = x -0.006Smiley Wink

   y= -0.03;   (or use y = y + 0.005Smiley Wink

end;

 

Then rerun the data step making that annotate and retry the map. It may take a little while to get a feel for how much to change things.

Note that the POSITION indicator is in relation to an (x,y) map point.

If you have a number of adjustments then Select /when may make the code easier to follow:

Select (County);

    when (xxx) do; x= x - 0.006; y= y+ 0.005; end;

    when (yyy) do; x= x + 0.01 ; y= y- 0.01; end;

   /* repeat for each county that needs a tweek*/

    otherwise; /* do nothing for the ones with no change desired*/

end;

 

Note I have a county label data set that I have manually set this way for pretty much every county as almost none of ours are rectangular. I have that set in a permanent library and bring it out when I need to match a data value for display.

And for school districts as well as multi-county adminstrative regions.

View solution in original post


All Replies
Solution
‎05-25-2017 09:48 AM
Grand Advisor
Posts: 10,050

Re: Really Need Assistance With Moving a Map Label in SAS EG 6.1.

Most of the code you posted is not needed. The key bit will be in this data step:

data work.combinedanno;
   set 
      work.nameanno (in=Name)
	work.Hospanno (in=Hosp) ;
   if Name then position = '2';

   Else if Hosp then position = '5';
  	if county=123 then position = 'F';
	if county=43 then position = '9';
	if county=143 then position = 'E';

   /* this is where you could put if statements to adjust
      the x and or y coordinates to display name or value
   */
run;

You will need to examine the coordinate from you map of the counties or hospitals that you do not like.

 

Then look them up in the above data set. You then conditional change either the x, the y or both coordinates.

Suppose County x label has a coordinate of x= -0.027 and y= -0.035 (which since the center of the map is usually (0,0) ) and I want to move that label a little bit to the left (negative) and up (positive) I would add something like:

If County = xxx then do;

   x= -0.033; ( or use x = x -0.006Smiley Wink

   y= -0.03;   (or use y = y + 0.005Smiley Wink

end;

 

Then rerun the data step making that annotate and retry the map. It may take a little while to get a feel for how much to change things.

Note that the POSITION indicator is in relation to an (x,y) map point.

If you have a number of adjustments then Select /when may make the code easier to follow:

Select (County);

    when (xxx) do; x= x - 0.006; y= y+ 0.005; end;

    when (yyy) do; x= x + 0.01 ; y= y- 0.01; end;

   /* repeat for each county that needs a tweek*/

    otherwise; /* do nothing for the ones with no change desired*/

end;

 

Note I have a county label data set that I have manually set this way for pretty much every county as almost none of ours are rectangular. I have that set in a permanent library and bring it out when I need to match a data value for display.

And for school districts as well as multi-county adminstrative regions.

Occasional Contributor
Posts: 7

Re: Really Need Assistance With Moving a Map Label in SAS EG 6.1.

Thank you so much for your assistance. It worked perfectly. I appreciate this so much.


☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 83 views
  • 0 likes
  • 2 in conversation