GEODIST Function
Returns the geodetic distance between two latitude and longitude coordinates.
| Categories: | Distance |
| CAS |
Syntax
Required Arguments
latitude
is a numeric constant, variable, or expression that specifies the coordinate of a given position north or south of the equator. Coordinates that are located north of the equator have positive values; coordinates that are located south of the equator have negative values.
| Restriction | If the value is expressed in degrees, it must be between 90 and –90. If the value is expressed in radians, it must be between pi/2 and –pi/2. |
longitude
is a numeric constant, variable, or expression that specifies the coordinate of a given position east or west of the prime meridian, which runs through Greenwich, England. Coordinates that are located east of the prime meridian have positive values; coordinates that are located west of the prime meridian have negative values.
| Restriction | If the value is expressed in degrees, it must be between 180 and –180. If the value is expressed in radians, it must be between pi and –pi. |
Optional Argument
option
specifies a character constant, variable, or expression that contains any of the following characters:
| M | specifies distance in miles. |
| K | specifies distance in kilometers. K is the default value for distance. |
| D | specifies that input values are expressed in degrees. D is the default for input values. |
| R | specifies that input values are expressed in radians. |
Details
Examples
Example 1: Calculating the Geodetic Distance in Kilometers
data _null_; distance=geodist(30.68, -88.25, 35.43, -82.55); put 'Distance= ' distance 'kilometers'; run;
Distance= 748.6529147 kilometers
Example 2: Calculating the Geodetic Distance in Miles Using the GEODIST Function with SAS
data _null_; distance=geodist(30.68, -88.25, 35.43, -82.55, 'M'); put 'Distance = ' distance 'miles'; run;
Distance = 465.29081088 miles
Example 3: Calculating the Geodetic Distance in Miles Using the GEODIST Function with CAS
data casuser.dist; input lat1 long1 lat2 long2; datalines; 35.2 -78.1 37.6 -79.8 ;
data casuser.dist2; set casuser.dist; Distance = geodist(lat1, long1, lat2, long2, 'DM'); put 'Distance = ' Distance 'miles'; run;
Example 4: Calculating the Geodetic Distance with Input Measured in Degrees
data _null_; input lat1 long1 lat2 long2; Distance = geodist(lat1, long1, lat2, long2, 'DM'); put 'Distance = ' Distance 'miles'; datalines; 35.2 -78.1 37.6 -79.8 ; run;
Distance = 190.72474282 miles
Example 5: Calculating the Geodetic Distance with Input Measured in Radians
data _null_;
input lat1 long1 lat2 long2;
pi = constant('pi');
lat1 = (pi*lat1)/180;
long1 = (pi*long1)/180;
lat2 = (pi*lat2)/180;
long2 = (pi*long2)/180;
Distance = geodist(lat1, long1, lat2, long2, 'RM');
put 'Distance= ' Distance 'miles';
datalines;
35.2 -78.1 37.6 -79.8
;
run; Distance= 190.72474282 miles