如何利用SAS繪制地圖
用SAS畫地圖需要用到gmap過程步,map=指定繪圖的map數(shù)據(jù)集,data=指定地圖的對(duì)應(yīng)數(shù)據(jù)集,id指定map數(shù)據(jù)集和對(duì)應(yīng)數(shù)據(jù)集中都有的變量,一般為各區(qū)域的代碼,作為兩個(gè)數(shù)據(jù)集的連接變量,分色級(jí)地圖(choro),是一個(gè)二維地圖,不同區(qū)域通過顯示不同深淺的顏色代表不同的數(shù)值。
/*繪制世界地圖*/
proc gmap map=mapsgfk.world data=mapsgfk.world;
id id;
choro id/ nolegend;
run;quit;
/*繪制中國地圖*/
proc gmap map=mapsgfk.china data=mapsgfk.china;
id id;
choro id/ nolegend;
run;quit;
/*只保留省和直轄市的邊界*/
proc gremove data=mapsgfk.china out=china;
by id1;
id id;
run;
proc gmap map=china data=china;
id id1;
choro id1 / nolegend;
run;quit;
/*給各省標(biāo)注上省名*/
data china_data;
set mapsgfk.china_attr;
keep id1 id1name;
run;
%annomac;
%maplabel(china,china_data,anno_label,id1name,id1,font=%str(arial),color=black,size=1.5,hsys=3);
proc gmap map=china data=china_data;
id id1;
choro id1 / nolegend anno=anno_label;
run;quit;
/*使用中文顯示各省的標(biāo)注,只需要使用id1nameU 并且轉(zhuǎn)碼即可顯示正確的中文*/
data china_data;
set mapsgfk.china_attr;
keep id1 id1nameU;
run;
%annomac;
%maplabel(china,china_data,anno_label,id1nameU,id1,font=%str(arial),color=black,size=1.5,hsys=3);
data anno_label;
set anno_label;
text=unicode(text);
run;
proc gmap map=china data=china_data;
id id1;
choro id1 / nolegend anno=anno_label;
run;quit;
請(qǐng)前往:http://lygongshang.com/TeacherV2.html?id=166