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: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 764 views
  • 0 likes
  • 2 in conversation