BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
craigwe85
Fluorite | Level 6

Hello, i currently have a table set up as which is called "store_long_lat"

image.png

I would like to calculate the distance between Latitude Longitude, and Latitude1 Longitude1.  and call it distance within the same table. There are 2000 rows in this table so I wold like to stray from the method where you have to input your Long and Lat values . I tried the below code and it produces a table with no data. Feel like am I close but just cant get an output to produce.

 

data distance; set store_long_lat;
input Latitude Longitude latitude1 longitude1;
distance = geodist(Latitude, Longitude, latitude1, longitude1);
put 'distance = ' Distance 'Miles'; datalines;
run;

 

I ran the below which produces a distance value inthe log but this does not work for my scenario:

 

data _null_;
distance = geodist(44.746052,-65.516649,43.68,-79.63);
put 'Distance= ' distance 'kilometers'; run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hello @craigwe85,

 

Just delete the INPUT and DATALINES statements. These are not required and in fact wrong because you read all data from a SAS dataset by means of a SET statement. Further, for a distance in miles you need to specify 'M' (case insensitive) as the fifth argument of the GEODIST function. Not sure how "insufficient memory" could be a problem here.

 

Edit: The PUT statement would write 2000 lines to the SAS log. Do you really want that?

View solution in original post

3 REPLIES 3
FreelanceReinh
Jade | Level 19

Hello @craigwe85,

 

Just delete the INPUT and DATALINES statements. These are not required and in fact wrong because you read all data from a SAS dataset by means of a SET statement. Further, for a distance in miles you need to specify 'M' (case insensitive) as the fifth argument of the GEODIST function. Not sure how "insufficient memory" could be a problem here.

 

Edit: The PUT statement would write 2000 lines to the SAS log. Do you really want that?

craigwe85
Fluorite | Level 6

Perfect thanks.. works great. Fairly new to SAS and was just taking bits and pieces to other things I have found.. insufficient Memory was not the error.. Must have clicked on wrong subject when it popped up.

 

Anyhow.. thanks a lot for your help

Reeza
Super User
data distance; 

set store_long_lat;

distance = geodist(Latitude, Longitude, latitude1, longitude1);

run;

proc print data=distance (obs=5);
run;

If you use SET it's unlikely you'll have an INPUT/INFIILE statement. 

 


@craigwe85 wrote:

Hello, i currently have a table set up as which is called "store_long_lat"

image.png

I would like to calculate the distance between Latitude Longitude, and Latitude1 Longitude1.  and call it distance within the same table. There are 2000 rows in this table so I wold like to stray from the method where you have to input your Long and Lat values . I tried the below code and it produces a table with no data. Feel like am I close but just cant get an output to produce.

 

data distance; set store_long_lat;
input Latitude Longitude latitude1 longitude1;
distance = geodist(Latitude, Longitude, latitude1, longitude1);
put 'distance = ' Distance 'Miles'; datalines;
run;

 

I ran the below which produces a distance value inthe log but this does not work for my scenario:

 

data _null_;
distance = geodist(44.746052,-65.516649,43.68,-79.63);
put 'Distance= ' distance 'kilometers'; run;

 


 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1087 views
  • 0 likes
  • 3 in conversation