EXAMPLE 9 Determine Customers Within Circular Radius
Purpose: Demonstrate how to use SAS/GRAPH PROC GINSIDE to determine whether customers are in a circular sales area of a given radius.
This example is short and sweet, really just a case of re-using techniques described in detail in two previous examples. This demonstrates that once you learn a “trick” you can apply it in other ways.
First, I get the longitude and latitude (in degrees) of the approximate center of my sales region and store that in a SAS data set. In this example I am grabbing the centroid of the ZIP code 27513 from the sashelp.zipcode data set, but you could get a center longitude and latitude any way that is convenient for you.
proc sql;
create table sales_region as
select zip, city, x*-1 as long, y as lat
from sashelp.zipcode
where (zip eq 27513);
quit; run;
Then create a data set containing the X and Y coordinates of a circle that has an n mile radius from that center point. This technique is described in more detail in Example 24, “Plotting Coverage Areas on a Map.”
%let radius_miles=40;
data sales_region; set sales_region;
retain xsys ysys '2' anno_flag 2 when 'a';
length text function $8 style color $20 text $25;
region_id=999999;
x=atan(1)/45 * long;
y=atan(1)/45 * lat;
d2r=3.1415926/180;
r=3958.739565;
xcen=long;
ycen=lat;
do degree=0 to 360 by 5;
if degree=0 then do;
function='poly';
style='empty';
line=1;
end;
else do;
function='polycont';
color=”&inside_color”;
end;
y=arsin(cos(degree*d2r)*sin(&radius_miles/R)*cos(ycen*d2r)+cos(&radius_miles/R)*sin(ycen*d2r))/d2r;
x=xcen+arsin(sin(degree*d2r)*sin(&radius_miles/R)/cos(y*d2r))/d2r;
x=atan(1)/45*x;
y=atan(1)/45*y;
output;
end;
run;
The rest of the code is the same as Example 8, “Determine Customers Within Map Borthders,” and here is the resulting map: