Hello, i currently have a table set up as which is called "store_long_lat"
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;
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?
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?
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
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"
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;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.