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

I have a dataset such as below.

 

ID     Base     x         y         z

01      0         1.1    2.3        2

02      0         1.9    3.3        2.3

03      1         5.1    2.5        6

04      0         1.1    4.3        4

05      0         3.1    2.3        5

06      0         1.7    1.3        2

 

Use Base=1 as the main ID, I want to calculate a Euclidean distance based on x, y and z. That is, I want to calculate the distance between each of ID whose base=0 and base=1 (ID 03) based on x,y ,z. I want to add one column dist, which is the distance between base=0 and base=1. The distance is defined as square root of sum of vector(x,y,z).

 

For example, distance between ID01 and ID03 is distance between [1.1, 2.3, 2] and [5.1, 2.5, 6]. I want to get a new dataset as below.

 

ID     Base     x         y         z          dist

01      0         1.1    2.3        2          distance(ID01,ID03)

02      0         1.9    3.3        2.3       distance(ID02,ID03)

03      1         5.1    2.5        6          distance(ID03,ID03)=0

04      0         1.1    4.3        4          distance(ID04,ID03)

05      0         3.1    2.3        5          distance(ID05,ID03)

06      0         1.7    1.3        2          distance(ID06,ID03)

 

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Try using PROC distance and filtering the results. 

View solution in original post

2 REPLIES 2
Reeza
Super User

Try using PROC distance and filtering the results. 

Rick_SAS
SAS Super FREQ

See the article "Distances between observations in two groups."  For your data, one group contains a single observation (03) and the other group contains the other observations.

 

For a fun application of distances between groups, see the article 'Is "La Quinta" Spanish for "Next to Denny's"?'

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 2 replies
  • 2183 views
  • 2 likes
  • 3 in conversation