/* Associate the libref MAPS with your SAS Map */ /* Library. This may already be done at your */ /* site when the SAS System is invoked. */ libname maps 'SAS-maps-library'; /* Create the sales information data set for */ /* selected cities by state. Note: The STATE */ /* and CITYFIPS values in the response data set */ /* must match the FIPS values that appear in */ /* the MAPS.USCITY and MAPS.US map data sets. */ /* In this example the sales data are already */ /* sorted by STATE and CITYFIPS. */ data sales; input state cityfips sales cityname $13.; cards; 40 3550 300 Oklahoma City 40 4780 200 Tulsa 48 1730 600 Dallas 48 3280 500 Houston 48 4140 250 Lubbock 48 6090 400 San Antonio run; /* Merge the sales information data set (SALES) */ /* with the MAPS.US data set to produce a data */ /* set called SALETERR with coordinates for */ /* only the states that appear in the SALES */ /* data set. */ data saleterr; merge sales(in=sales) maps.us(in=inus); by state; if sales and inus; /* Sort MAPS.USCITY by STATE and CITYFIPS and */ /* create a data set called UCITY. The data set */ /* must be sorted before it can be merged with */ /* the SALES data set. */ proc sort data=maps.uscity out=ucity; by state cityfips; /* Merge the SALES and UCITY data sets to */ /* produce a data set with the coordinates of */ /* only the cities that appear in the sales */ /* information data set. Assign a new STATE */ /* value, unique to each city by adding the */ /* values of STATE and CITYFIPS/100,000. */ /* Dividing CITYFIPS by a large value is */ /* necessary to prevent duplicate values for */ /* STATE. For example, adding the values of */ /* STATE=10 and CITYFIPS=150 would yield the */ /* same result as adding STATE=30 and */ /* CITYFIPS=130. */ data ctycoord; merge sales(in=insales) ucity(in=incity); by state cityfips; if insales and incity; state=state+(cityfips/100000); run; /* Create the map data set MYMAP by combining */ /* the SALETERR and CTYCOORD data sets. */ data mymap; set saleterr ctycoord; /* Take the response data set SALES and assign */ /* values to the STATE variable that match the */ /* values in the UCITY data set by adding the */ /* values of STATE and CITYFIPS/100,000. */ data newsales; set sales; state=state+(cityfips/100000); run; /* Create the map using the new response data */ /* set NEWSALES and the map data set MYMAP. */ /* The ALL option must be included on the PROC */ /* GMAP statement so the Oklahoma and Texas */ /* boundaries are drawn. The DISCRETE option */ /* must be specified on the BLOCK statement so */ /* the procedure will treat each sales value as */ /* a separate category. */ goptions ftext=swiss; title1 'Sales for Oklahoma and Texas'; proc gmap data=newsales map=mymap all; id state; block sales/discrete blocksize=3 yview=-1; /* patterns for the blocks */ pattern1 v=solid c=black; pattern2 v=r1 c=black; pattern3 v=empty c=black; pattern4 v=x1 c=black; pattern5 v=x4 c=black; pattern6 v=r3 c=black; run;