- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Try using PROC distance and filtering the results.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Try using PROC distance and filtering the results.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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"?'