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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

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