- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Ok, I am extremely new to SAS. In fact, this is the 1st time I've used it since I took the class. We use EG 6.1 I have to create the attached map or something close to it with the # of hospitals in each county here in Ohio. I've managed to find examples of code to create the Ohio Map. I've also found code to shade it by the number of hospitals. The issue that i am having is being able to shade the map and label it at the same time. I even managed to import a field into a dataset with the number of hospitals. When i try to combine the 2, i get an error because the variable i assigned is not working (I guess). I'm using the CNTYNAME set and then i added the a field hospitals, which had the number of hospitals for that county. I also added another field called CNTYHOSP that combined the name & # of hospitals in the county together. Then i imported that back into SAS and called it OHCNTYNAME. All of our SAS experts are out of the office until Monday, so...any advice would be greatly appreciated.
This code gave me the county name labels
/****************************************************************/
/* This sample program annotates the county names on a map */
/* of Ohio. It uses the %MAPLABEL annotate macro to create */
/* the annotate data set used with the GMAP procedure. */
/* This annotate macro is available beginning with Version 9 of */
/* the SAS System. */
/****************************************************************/
/* Set the graphics environment */
goptions reset=all cback=white border htitle=12pt htext=10pt;
/* Create a projected map of Ohio with county boundaries */
proc gproject data=maps.counties out=ohio;
/* State FIPS for Ohio */
where state=39;
id state county;
run;
quit;
/* Create a data set containing the names of the counties */
/* in Ohio. */
data ohnames;
set WORK.OHCNTYNAME2;
/* State FIPS code for Ohio */
where state=39;
run;
/* Make the annotate macros available */
%annomac;
/* Use the MAPLABEL annotate macro to create an annotate data set */
/* to label the counties. */
/* The macro parameters are: */
/* Input Map data set. */
/* Attribute data set that contains variable for the label. */
/* Resulting output data set for use in ANNO= in GMAP. */
/* Variable for label on. Can be text or numeric. */
/* Space-separated list of IDs that the map and attribute */
/* data sets are sorted on. */
/* FONT= Font for the label. */
/* COLOR= Color of the label. Default is BLACK. */
/* SIZE= Size of the label. Default is 1. */
/* HSYS= UNIT system for SIZE=. Default is 3 (PERCENT). */
%maplabel(ohio,ohnames,anno,cntyhosp,state county,font='Albany AMT/',
color=black,size=1.1);
title1 "County Map of Ohio";
pattern1 v=me c=black r=15;
/* Generate a county map of Ohio with county labels */
proc gmap data=ohio map=ohio;
id state county;
choro county / anno=anno nolegend coutline=grayaa;
run;
quit;
THIS ONE ALLOWED ME TO GET THE LEGEND AND COLOR IT
value ohiohos_
1 = '1'
2 = '2'
3 - 5 = '3 - 5'
6 - 21 = '6-21'
;
run;
* 2000 census population, New York State counties;
data numofhos0;
input county 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;
* fill patterns for the map areas (gray-scale fills);
pattern1 v=s c=grayff;
pattern2 v=s c=grayda;
pattern3 v=s c=grayaa;
pattern4 v=s c=gray68;
proc gmap
data=numofhos0
map=ohio;
id county;
choro ohiohos / discrete;
format ohiohos ohiohos_.;
title1 'NUMBER OF OHIO HOSPITALS';
run;
quit;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Please post the code and error from the log. Paste it into a code box opened with the forum {i} menu icon as some of the diagnostic information may be position sensitive and pasting into the main message area changes the locations of some items.
You may well need to modify the output data set created by maplabel.
It appears that you have two items you want to display: the county name and a numeric result. That means your annotate will work better with both pieces of data in one location. A key bit of information that the %maplabel macro doesn't do is set the POSITION of displayed text. The Position annotate variable controls how your text is displayed in relation to the x,y coordinates use. For your example may you may want to set the position to '2' for the county name (position is a character varialbe). 2 says to center the text horizontally on the coordinates but place it vertically one text cell above the coordinate. The for the same coordinate location you would want to display the count text at position '8' which is centered below the coordinate pair. If the '2' and '8' create too much space you might try 'B' and 'E' depending on your font sizes which have less vertical displacement. Note that you can also use an If/Then or Select statement to conditionally assign Position values to adjust appearance for specific county name/value pairs.
If you think you may be doing this type of thing very often I strongly suggest that you create a custom set of maplabel points for the county starting with the result of the %maplabel macro. The maplabel macro is helpful but your counties around the lake and a few others like Auglaize and few others may benefit from a little tweeking.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you so much for a reply. I'll paste the last effort because i keep trying and failing, but hey this is literally my first time. I also attached my spreadsheet. I added the columns to it so that i could try to have everything in one place.
1 The SAS System 09:20 Thursday, May 4, 2017 1 ;*';*";*/;quit;run; 2 OPTIONS PAGENO=MIN; 3 %LET _CLIENTTASKLABEL='Program2'; 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 24 /****************************************************************/ 25 /* This sample program annotates the county names on a map */ 26 /* of Ohio. It uses the %MAPLABEL annotate macro to create */ 27 /* the annotate data set used with the GMAP procedure. */ 28 /* This annotate macro is available beginning with Version 9 of */ 29 /* the SAS System. */ 30 /****************************************************************/ 31 32 /* Set the graphics environment */ 33 goptions reset=all cback=white border htitle=12pt htext=10pt; 34 35 /* Create a projected map of Ohio with county boundaries */ 36 proc gproject data=maps.counties out=ohio; 37 38 /* State FIPS for Ohio */ 39 where state=39; 40 id state county; 41 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.04 seconds 42 quit; 43 2 The SAS System 09:20 Thursday, May 4, 2017 44 /* Create a data set containing the names of the counties */ 45 /* in Ohio. */ 46 data ohnames; 47 set WORK.OHCNTYNAME; 48 49 /* State FIPS code for Ohio */ 50 where state=39; 51 run; NOTE: There were 88 observations read from the data set WORK.OHCNTYNAME. WHERE state=39; NOTE: The data set WORK.OHNAMES has 88 observations and 11 variables. NOTE: Compressing data set WORK.OHNAMES 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 52 53 proc format; 54 value ohiohos_ 55 1 = '1' 56 2 = '2' 57 3 - 5 = '3 - 5' 58 6 - 21 = '6-21' 59 ; NOTE: Format OHIOHOS_ is already on the library WORK.FORMATS. NOTE: Format OHIOHOS_ has been output. 60 run; NOTE: PROCEDURE FORMAT used (Total process time): real time 0.00 seconds cpu time 0.01 seconds 61 * Ohio hospitals by county; 62 data numofhos0; 63 input county ohiohos @@; 64 datalines; NOTE: Compression was disabled for data set WORK.NUMOFHOS0 because compression overhead would increase the size of the data set. NOTE: Invalid data for county in line 67 2-3. NOTE: Invalid data for ohiohos in line 67 5-8. RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0 67 /* Make the annotate macros available */ county=. ohiohos=. _ERROR_=1 _N_=1 NOTE: Invalid data for county in line 67 10-12. NOTE: Invalid data for ohiohos in line 67 14-21. NOTE: Invalid data errors for file CARDS occurred outside the printed range. NOTE: Increase available buffer lines with the INFILE n= option. county=. ohiohos=. _ERROR_=1 _N_=2 NOTE: Invalid data for county in line 67 23-28. NOTE: Invalid data for ohiohos in line 67 30-38. NOTE: Invalid data errors for file CARDS occurred outside the printed range. NOTE: Increase available buffer lines with the INFILE n= option. county=. ohiohos=. _ERROR_=1 _N_=3 NOTE: Invalid data for county in line 67 40-41. 3 The SAS System 09:20 Thursday, May 4, 2017 NOTE: LOST CARD. RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0 68 %annomac; NOTE: Invalid data errors for file CARDS occurred outside the printed range. NOTE: Increase available buffer lines with the INFILE n= option. county=. ohiohos=. _ERROR_=1 _N_=4 NOTE: SAS went to a new line when INPUT statement reached past the end of a line. NOTE: The data set WORK.NUMOFHOS0 has 3 observations and 2 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.01 seconds 68 %annomac; *** ANNOTATE macros are now available *** 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) 69 70 /* Use the MAPLABEL annotate macro to create an annotate data set */ 71 /* to label the counties. */ 72 /* The macro parameters are: */ 73 /* Input Map data set. */ 74 /* Attribute data set that contains variable for the label. */ 75 /* Resulting output data set for use in ANNO= in GMAP. */ 76 /* Variable for label on. Can be text or numeric. */ 77 /* Space-separated list of IDs that the map and attribute */ 78 /* data sets are sorted on. */ 79 /* FONT= Font for the label. */ 80 /* COLOR= Color of the label. Default is BLACK. */ 81 /* SIZE= Size of the label. Default is 1. */ 82 /* HSYS= UNIT system for SIZE=. Default is 3 (PERCENT). */ 83 84 %maplabel(ohio,ohnames,anno,cntyhosp,state county,font='Albany AMT/', 85 color=black,size=1.1); 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.DATA7 has 4247 observations and 6 variables. NOTE: Compressing data set WORK.DATA7 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.DATA7. 4 The SAS System 09:20 Thursday, May 4, 2017 NOTE: The data set WORK.ANNO has 88 observations and 9 variables. NOTE: Compressing data set WORK.ANNO 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.ANNO. NOTE: The data set WORK.ANNO has 88 observations and 5 variables. NOTE: Compressing data set WORK.ANNO 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.DATA7 because compression overhead would increase the size of the data set. NOTE: There were 88 observations read from the data set WORK.ANNO. NOTE: There were 4247 observations read from the data set WORK.DATA7. NOTE: The data set WORK.DATA7 has 184 observations and 4 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.DATA7. NOTE: The data set WORK.DATA7 has 184 observations and 4 variables. 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.ANNO because compression overhead would increase the size of the data set. NOTE: There were 184 observations read from the data set WORK.DATA7. NOTE: The data set WORK.ANNO has 88 observations and 4 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.DATA8 has 88 observations and 11 variables. NOTE: Compressing data set WORK.DATA8 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.00 seconds NOTE: There were 88 observations read from the data set WORK.DATA8. NOTE: The data set WORK.DATA8 has 88 observations and 11 variables. 5 The SAS System 09:20 Thursday, May 4, 2017 NOTE: Compressing data set WORK.DATA8 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.05 seconds cpu time 0.01 seconds NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column). 85:148 WARNING: Multiple lengths were specified for the BY variable STATE by input data sets. This might cause unexpected results. 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.ANNO. NOTE: There were 88 observations read from the data set WORK.DATA8. NOTE: The data set WORK.ANNO has 88 observations and 15 variables. NOTE: Compressing data set WORK.ANNO 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.ANNO. NOTE: 0 observations with duplicate key values were deleted. NOTE: The data set WORK.ANNO has 88 observations and 15 variables. NOTE: Compressing data set WORK.ANNO 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 86 87 title1 "County Map of Ohio"; 88 pattern1 v=me c=black r=15; 89 90 /* Generate a county map of Ohio with county labels */ 91 proc gmap data=ohio map=ohio; 92 id state county; 93 choro county / anno=anno nolegend coutline=grayaa; 94 run; WARNING: Some observations were discarded when charting COUNTY. Only first matching observation was used. Use STATISTIC= option for summary statistics. NOTE: 60463 bytes written to 95 quit; NOTE: There were 88 observations read from the data set WORK.ANNO. NOTE: PROCEDURE GMAP used (Total process time): real time 0.28 seconds cpu time 0.25 seconds 96 97 98 6 The SAS System 09:20 Thursday, May 4, 2017 99 GOPTIONS NOACCESSIBLE; 100 %LET _CLIENTTASKLABEL=; 101 %LET _CLIENTPROJECTPATH=; 102 %LET _CLIENTPROJECTNAME=; 103 %LET _SASPROGRAMFILE=; 104 105 ;*';*";*/;quit;run; 106 ODS _ALL_ CLOSE; 107 108 109 QUIT; RUN; 110
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
A couple of comments:
Unless you need to match something with latitude and longitude (in unprojected radians) you do not need the gproject step because you could use MAPS.USCOUNTY to select an already projected map dataset.
Your code example shows stuff like this from the data step that should build the NumOfHos data set.
NOTE: Invalid data for ohiohos in line 67 5-8. RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0 67 /* Make the annotate macros available */ county=. ohiohos=. _ERROR_=1 _N_=1 NOTE: Invalid data for county in line 67 10-12. NOTE: Invalid data for ohiohos in line 67 14-21.
Your previosly posted example data set does not generate those warnings. Invalid data for county is likely going to cause issues later.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Please see:
data work.Ohio; set maps.uscounty; where state=39; run; proc format library=work; value ohiohos_ 1 = '1' 2 = '2' 3 - 5 = '3 - 5' 6 - 21 = '6-21' ; 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/', color=black,size=1.1); %maplabel(work.ohio,work.numofhos0,work.Hospanno,HospText, county,font='Albany AMT/', color=black,size=1.1); data work.combinedanno; set work.nameanno (in=Name) work.Hospanno (in=Hosp); if Name then position = '2'; Else if Hosp then position = '8'; /* this is where you could put if statements to adjust the x and or y coordinates to display name or value */ run; title1 "County Map of Ohio"; /* Generate a county map of Ohio with county labels */ proc gmap data=work.numofhos0 map=work.ohio; id county; choro ohiohos / anno=work.combinedanno discrete coutline=grayaa ; format ohiohos ohiohos_.; label ohiohos= "Number of Hospitals"; run; quit; title;
I explicitly use the WORK library for a number of reasons.
Note that since you are only doing one state I dropped that from things.
I don't use ACTIVEX for a device because it has issues in some output destinations so you may want to change that if odd things start happening.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I just wanted to say thank you so much. I did make a couple of changes. I added the gproject code because it seemed to produce a straighter map of Ohio. We switched out the countynm varible for ohiohos to display the number of hospitals and added some border lines since some of the counties had the same number of hospitals. We will work on the color scheme, but thank you all so much. Hopefully i can get to the point where i am helping others. I added the pics of the map from your code and my code.
proc gproject data=maps.counties out=ohio; /* State FIPS for Ohio */ where state=39; id state county; run; quit; proc format library=work; value ohiohos_ 1 = '1' 2 = '2' 3 - 5 = '3 - 5' 6 - 21 = '6-21' ; 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/', color=black,size=1.5); %maplabel(work.ohio,work.numofhos0,work.Hospanno,ohiohos, county,font='Albany AMT/', 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 = '8'; /* 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 c=grayff; pattern2 v=s c=grayda; pattern3 v=s c=grayaa; pattern4 v=s c=gray68; pattern5 v=s c=bibg; 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; title;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You do have some label points to identify for a few of the countyies, mostly around the lake.
I would probably make the font on the number of hospitals either large, bold or both if that is key information to impart.
You may also want to investicate CBOX annotate variable to set a color behind the text as black text on medium or dark gray is hard to read. With CBOx you could set a white (or other) background color to improve contrast.
And if you're happy I'm happy.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.CENTROIDS work.nameanno (in=Name) WORK.CENTROIDS work.Hospanno (in=Hosp); if Name then position = '2'; Else if Hosp then position = '8'; /* 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=grayda; pattern3 v=s color=biy; pattern4 v=s color=bisque; pattern5 v=s c=bibg; pattern6 v=s color=cyan; 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; title;
I've been off for a couple of days... anyway, added some code that I found about centering the county labels, which is the centroid bit. Now the issue remains as previous, that the lake counties are not formatting proprely. Is there a way to scale the output to make it larger? I'm thinking that i could get the labels to fit if the output size of the map was bigger, maybe? Still working on color scheme
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello everyone again. Hopefully this will be my last post on this subject. My map looks fairly good thanks to the help of all of you out there. I just have one problem and i can't seem to figure it out. It's the labels for the Ottawa (123) & Erie (43). See how messed they are. I tried playing with the postion code and it managed to the county & number close to each other. I someone can help me figure out those 2 counties. I tried if then statements but i
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.7); %maplabel(work.ohio,work.numofhos0,work.Hospanno,ohiohos, county,font='Albany AMT/''boldt', color=black,size=1.8); data work.combinedanno; set WORK.CENTROIDS work.nameanno (in=Name) WORK.CENTROIDS work.Hospanno (in=Hosp); if Name then position = '2.1'; Else if Hosp then position = '5'; /* 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=grayda; pattern3 v=s color=biy; pattern4 v=s color=bisque; pattern5 v=s c=bibg; pattern6 v=s color=cyan; 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; title;
guess i can;t figure out which variable i need to alter. Thanks again everyone, take care