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.

RestrictionIf 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.

RestrictionIf 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:

Mspecifies distance in miles.
Kspecifies distance in kilometers. K is the default value for distance.
Dspecifies that input values are expressed in degrees. D is the default for input values.
Rspecifies 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.
Example, Calculating the Geodetic Distance in Miles Using the GEODIST Function with CAS shows how to run the GEODIST function in CAS.
Some language elements are supported in SAS but not in CAS. An example is the DATALINES statement. Some examples in this document use DATALINES in SAS to create a data set using the CAS engine. For more information, see Functions in SAS and CAS.

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 Using the GEODIST Function with SAS

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 in Miles Using the GEODIST Function with CAS

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). The first section of code in this example runs in SAS and creates the data set, dist, with the CAS engine. The second section of code runs in CAS, accesses the data in dist that is in CAS, and then creates the dist2 data set.
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

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 5: 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.
Last updated: March 16, 2017