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

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.

 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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)

PG

View solution in original post

1 REPLY 1
PGStats
Opal | Level 21

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)

PG

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
  • 1 reply
  • 830 views
  • 0 likes
  • 2 in conversation