Usage Note 36198: New function GEODIST in SAS® 9.2 returns the geodetic distance between two latitude and longitude coordinates
In SAS 9.2, the new GEODIST function returns the geodetic distance in kilometers or miles between two latitude and longitude coordinates. Kilometers is the default, but you can obtain the distance in miles by selecting the 'M' option as documented.
The default input values are degrees, but the 'R' option can be used to indicate that the input values are in radians rather than degrees.
Below is a link to the documentation for the function.
The GEODIST Function
The sample code on the Full Code tab illustrates the use of the GEODIST function.
There is also a function called ZIPCITYDISTANCE that is new in SAS 9.2. Information on that function can be obtained by scrolling down the Contents listing that can be found to the left of the documentation on the GEODIST function available from the link above.
Below is a link to the SAS note explaining how to calculate the distance prior to SAS 9.2.
Click to go to SAS Note 5325
Operating System and Release Information
| SAS System | Base SAS | z/OS | 9.2 TS1M0 | |
| Microsoft® Windows® for 64-Bit Itanium-based Systems | 9.2 TS1M0 | |
| Microsoft Windows Server 2003 Datacenter 64-bit Edition | 9.2 TS1M0 | |
| Microsoft Windows Server 2003 Enterprise 64-bit Edition | 9.2 TS1M0 | |
| Microsoft Windows XP 64-bit Edition | 9.2 TS1M0 | |
| Microsoft® Windows® for x64 | 9.2 TS1M0 | |
| Microsoft Windows Server 2003 Datacenter Edition | 9.2 TS1M0 | |
| Microsoft Windows Server 2003 Enterprise Edition | 9.2 TS1M0 | |
| Microsoft Windows Server 2003 Standard Edition | 9.2 TS1M0 | |
| Microsoft Windows XP Professional | 9.2 TS1M0 | |
| Windows Vista | 9.2 TS1M0 | |
| 64-bit Enabled AIX | 9.2 TS1M0 | |
| 64-bit Enabled HP-UX | 9.2 TS1M0 | |
| 64-bit Enabled Solaris | 9.2 TS1M0 | |
| HP-UX IPF | 9.2 TS1M0 | |
| Linux | 9.2 TS1M0 | |
| Linux for x64 | 9.2 TS1M0 | |
| OpenVMS on HP Integrity | 9.2 TS1M0 | |
| Solaris for x64 | 9.2 TS1M0 | |
*
For software releases that are not yet generally available, the Fixed
Release is the software release in which the problem is planned to be
fixed.
The syntax for the function is below.
GEODIST(latitude-1, longitude-1, latitude-2, longitude-2, );
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;
SAS writes the following output to the log:
Distance= 748.6529147 kilometers
Example 2: Calculating the Geodetic Distance in Miles
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
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
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
The new GEODIST function in SAS® 9.2 returns the geodetic distance between two latitude and longitude coordinates.
| Type: | Usage Note |
| Priority: | |
| Topic: | SAS Reference ==> Functions ==> State and ZIP Code
|
| Date Modified: | 2010-08-02 15:32:41 |
| Date Created: | 2009-06-10 14:16:25 |