Geodist returns a distance of 0 (two different latitude&longitude combinations)

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

Geodist returns a distance of 0 (two different latitude&longitude combinations)

Hi Guys,

This is my sas code:

data tmp;

flight_distance=geodist(-0.14, -78, 2.74, 102, 'M');

run;

This code returns flight_distance=0. However, in google map, you can see the two locations (actually two airports--KUL & UIO) are thousands of miles away. So my question is, why I'm getting 0 with geodist?

Thanks


Accepted Solutions
Solution
‎11-13-2014 02:14 PM
Super User
Posts: 3,106

Re: Geodist returns a distance of 0 (two different latitude&longitude combinations)

Interesting. In SAS 9.3 M1 I get 0:

29         data _null_;

30         flight_distance=geodist(-0.14, -78,2.74, 102, 'M');

31         put flight_distance=;

32         run;

flight_distance=0

NOTE: DATA statement used (Total process time):

real time           0.07 seconds   
cpu time            0.00 seconds


In SAS 9.4 M2 I get:

28        

29         data _null_;

30         flight_distance=geodist(-0.14, -78,2.74, 102, 'M');

31         put flight_distance=;

32         run;

flight_distance=12253.844639

NOTE: DATA statement
used (Total process time):

real time           0.09 seconds

cpu time            0.00 seconds


Looks like it is a bug in SAS 9.3 M1.





View solution in original post


All Replies
Trusted Advisor
Posts: 1,300

Re: Geodist returns a distance of 0 (two different latitude&longitude combinations)

I get the expected answer, roughly 12k miles.

New Contributor
Posts: 3

Re: Geodist returns a distance of 0 (two different latitude&longitude combinations)

Thanks for trying it out on your computer.

I do use the exact same statement, meaning I haven't simplified my example. However, it returns 0. FYI, I used it with SAS ENTERPRISE GUIDE 5.1.

Capture.PNGCapture.PNG

Respected Advisor
Posts: 3,124

Re: Geodist returns a distance of 0 (two different latitude&longitude combinations)

I am using EG 5.1 with 9.3M2 and 9.4M1, and I also can't repeat your issue. I have noticed that your program has a warning sign. What is the warning message in the log?

New Contributor
Posts: 3

Re: Geodist returns a distance of 0 (two different latitude&longitude combinations)

WARNING: Style XXX not found; Default style will be used instead.

That's the warning message. Not really relevant to my issue.

Thanks

Solution
‎11-13-2014 02:14 PM
Super User
Posts: 3,106

Re: Geodist returns a distance of 0 (two different latitude&longitude combinations)

Interesting. In SAS 9.3 M1 I get 0:

29         data _null_;

30         flight_distance=geodist(-0.14, -78,2.74, 102, 'M');

31         put flight_distance=;

32         run;

flight_distance=0

NOTE: DATA statement used (Total process time):

real time           0.07 seconds   
cpu time            0.00 seconds


In SAS 9.4 M2 I get:

28        

29         data _null_;

30         flight_distance=geodist(-0.14, -78,2.74, 102, 'M');

31         put flight_distance=;

32         run;

flight_distance=12253.844639

NOTE: DATA statement
used (Total process time):

real time           0.09 seconds

cpu time            0.00 seconds


Looks like it is a bug in SAS 9.3 M1.





Super User
Posts: 17,829

Re: Geodist returns a distance of 0 (two different latitude&longitude combinations)

I can repeat it:

SAS 9.3 TS1M0

264  data tmp;

265  flight_distance=geodist(-0.14, -78, 2.74, 102, 'M');

266  put 'Flight Distance=' flight_distance;

267  run;

Flight Distance=0

NOTE: The data set WORK.TMP has 1 observations and 1 variables.

NOTE: DATA statement used (Total process time):

      real time           0.03 seconds

      cpu time            0.01 seconds

Super User
Posts: 10,500

Re: Geodist returns a distance of 0 (two different latitude&longitude combinations)

12253.844 in SAS 9.3 TS1M2

So we may know this was fixed between M1 and M2.

Trusted Advisor
Posts: 1,300

Re: Geodist returns a distance of 0 (two different latitude&longitude combinations)

It is not as accurate as the geodist function, but you can use the great circle distance formula to get the distance in the absence of the geodist function working properly.

proc fcmp outlib=work.func.geox;

   function geodistx(lat1, lng1, lat2, lng2);

      return ( 3949.99 * arcos(sin(radx(lat1)) * sin(radx(lat2)) +

               cos(radx(lat1)) * cos(radx(lat2)) *

               cos(radx(lng1) - radx(lng2))) );

   endsub;

   function radx(deg);

      return (atan(1)/45 * deg);

   endsub;

run;

options append=(cmplib=work.func);

56 %put %sysfunc(geodist( -0.14, -78, 2.74, 102, 'M'));

12253.8446385712

57 %put %sysfunc(geodistx( -0.14, -78, 2.74, 102));

12230.0147053589

Respected Advisor
Posts: 4,649

Re: Geodist returns a distance of 0 (two different latitude&longitude combinations)

Same here, with SAS 9.4 TS1M1. Also, I used geodist with SAS 9.3 and didn't notice anything wrong.

You may have oversimplified your example to the point of removing the problem?

PG

PG
Super User
Posts: 17,829

Re: Geodist returns a distance of 0 (two different latitude&longitude combinations)

You should probably report this to Tech Support, see the Submit a problem report in the very fine print at the bottom of the page.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 10 replies
  • 543 views
  • 6 likes
  • 7 in conversation