是一个制作地图,控制显示色彩的问题,先把code帖在这:
/* Set the graphics environment */
goptions reset=all cback=white border htitle=12pt htext=10pt;
/* Create a sample data set */
data products;
input State County Count;
datalines;
17 19 3
17 29 1
17 31 124
17 37 3
17 43 22
17 77 3
17 89 2
17 97 5
17 113 6
17 115 4
17 119 1
17 143 3
17 161 4
17 167 8
17 201 4
18 3 4
18 5 3
18 35 1
18 39 4
18 63 3
18 67 3
18 85 2
18 89 5
18 97 32
18 127 1
18 141 4
18 157 2
18 163 2
18 167 1
26 21 1
26 49 2
26 65 1
26 75 5
26 77 8
26 81 4
26 83 1
26 99 11
26 101 1
26 103 1
26 111 4
26 125 12
26 139 4
26 145 6
26 155 8
26 161 5
26 163 26
39 9 6
39 17 6
39 35 34
39 45 3
39 49 28
39 57 2
39 61 21
39 63 3
39 83 1
39 89 2
39 93 1
39 95 9
39 99 4
39 109 2
39 113 14
39 149 2
39 151 3
39 153 9
39 159 1
39 173 1
55 9 2
55 25 12
55 63 1
55 79 25
55 101 4
55 117 2
55 127 2
55 139 2
;
run;
/* Create a data set that contains the map boundaries */
/* for only the counties in the response data set */
/* also create a data set for only the states which */
/* are contained in the response data */
data counties(drop=count test) selstate(keep=state);
retain test 0 ;
merge products(in=inprod) maps.counties(in=inmap);
by state county ;
if inprod and inmap;
/* Determine which states are included in the response data */
if state ^= test then do;
output selstate;
test=state;
end;
output counties;
run;
/* Get the unprojected coordinates for the states */
data states;
merge maps.states selstate(in=inprod);
by state;
if inprod;
run;
/* Concatenate states with counties map data set */
/* for projection */
data newmap;
set states counties;
run;
/* Project the map coordinates and create a new map data set */
proc gproject data=newmap out=newmap;
id state county;
run;
quit;
******************************************************************;
画线以上部分是准备数据集,可以不考虑太多,重点在下面的部分。
/* Specify distribution format */
proc format;
value dist 1-5='1-5' 6-10='6-10' 11-high='over 10';
run;
title 'Products Installed in the Great Lakes Region';
title2 h=10pt 'By County';
pattern1 c=red;
pattern2 c=blue;
pattern3 c=green;
/* Generate the map */
proc gmap data=products map=newmap all;
id state county;
choro count / discrete;
format count dist.;
label count='# of Products';
run;
quit;
运行这部分code后,数据会在地图上显示为red (count为1-5的显示为红色),blue (count 为6-10的蓝色), green (count为10以上的显示绿色)。
因为最上面的数据集是用一个macro产生的,有好几十个,其中一些count会缺失6-10这一组值,如果缺失了6-10这一组值,做出来的地图会是:count值为1-5的还显示为红色,数据集count 6-10缺失的,不显示,不占用pattern2控制的颜色,这时,count为10以上的使用pattern2控制的颜色,显示为蓝色(而不是先前的绿色)。结果,不同的地图,颜色和数值的对应不一致。
有没有办法,让地图上的颜色显示总是一致的?就是说,即使count值6-10缺失,cont值10以上也总是显示为green。
因为前面一部分产生的数据集比较多,不能用一个一个处理的简单办法,只能通过code控制。
谢谢!