GEODIST Function

Returns the geodetic distance between two latitude and longitude coordinates.

Category: Distance

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

The GEODIST function computes the geodetic distance between any two arbitrary latitude and longitude coordinates. Input values can be expressed in degrees or in radians.

Examples

Example 1: Calculating the Geodetic Distance in Kilometers

The following example shows the geodetic distance in kilometers between Mobile, AL (latitude 30.68 N, longitude 88.25 W), and Asheville, NC (latitude 35.43 N, longitude 82.55 W). The program uses the default K option.
data _null_;
   distance=geodist(30.68, -88.25, 35.43, -82.55);
   put 'Distance= ' distance 'kilometers';
run;
SAS writes the following output to the log:
Distance= 748.6529147 kilometers

Example 2: Calculating the Geodetic Distance in Miles

The following example uses the M option to compute the geodetic distance in miles between Mobile, AL (latitude 30.68 N, longitude 88.25 W), and Asheville, NC (latitude 35.43 N, longitude 82.55 W).
data _null_;
   distance=geodist(30.68, -88.25, 35.43, -82.55, 'M');
   put 'Distance = ' distance 'miles';
run;
SAS writes the following output to the log:
Distance = 465.29081088 miles

Example 3: Calculating the Geodetic Distance with Input Measured in Degrees

The following example uses latitude and longitude values that are expressed in degrees to compute the geodetic distance between two locations. Both the D and the M options are specified in the program.
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; 
SAS writes the following output to the log:
Distance = 190.72474282 miles

Example 4: Calculating the Geodetic Distance with Input Measured in Radians

The following example uses latitude and longitude values that are expressed in radians to compute the geodetic distance between two locations. The program converts degrees to radians before executing the GEODIST function. Both the R and the M options are specified in this program.
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; 
SAS writes the following output to the log:
Distance= 190.72474282 miles

References

Vincenty, T. “Direct and Inverse Solutions of Geodesics on the Ellipsoid with Application of Nested Equations.” 1975. Survey Review 22: 99–93.