SAS/IML Software and Matrix Computations

Statistical programming, matrix languages, and more
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-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

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