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)
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.