I have a dataset where the variables look like this:
latitude longitude latitude1 longitude1 latitude2 longitude2 latitude3 longitude3
until you reach latitude99 and longitude99.
What I wish to do is calculate the distance between latitude and longitude and each of the pairs from 1 to 99. For example:
distance1 = geodist(latitude, longitude, latitude1, longitude1)
distance2 = geodist(latitude, longitude, latitude2, longitude2)
distance99 = geodist(latitude, longitude, latitude99, longitude99)
Obviously I do not want to manually type out each distance variable until distance99, is there a faster way to do this? Thank you.
Use arrays:
data want;
array lat_ latitude1-latitude99;
array lon_ longitude1-longitude99;
array dist_ distance1-distance99;
set myDataset;
do i = 1 to dim(dist_);
dist_{i} = geodist(latitude, longitude, lat_{i}, lon_{i});
end;
drop i;
run;
(untested)
Use arrays:
data want;
array lat_ latitude1-latitude99;
array lon_ longitude1-longitude99;
array dist_ distance1-distance99;
set myDataset;
do i = 1 to dim(dist_);
dist_{i} = geodist(latitude, longitude, lat_{i}, lon_{i});
end;
drop i;
run;
(untested)
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.