BookmarkSubscribeRSS Feed
Himanshu007
Obsidian | Level 7

I have the following data

 

 

PS      Lat            Long         SLOT

abc    75.8233    26.2454     1
abc    75.4785    26.4589     1

abc    75.5495    26.4679     1
abc    75.4875    26.8997     2
abc    75.5649    26.7268     2
abc    75.5666    26.8647     2
xyz    75.4875    26.3842      1
xyz    75.4937    26.5877      1
xyz    75.8473    26.3971      1
xyz    75.7861    26.6884       2

 

 

Now I want a new column which shows the distances in the following way:

All the points with PS=abc and Slot=1  should have their distances calculated from the first point of this group(i.e.,  75.8233    26.2454), similarly all the points with PS=abc and Slot=2 should have their distances calculated from the first point of this group(i.e., 75.4875    26.8997) and so on.

So please suggest me a solution for this.

3 REPLIES 3
Himanshu007
Obsidian | Level 7
But this function is only there for finding the distances my concern is how to fix one point from each group(group means same PS and same Slot) as a fixed reference point from which the other distances are to be found
ballardw
Super User

Assuming your data are sorted by PS and Slot as implied by the example:

 

data want;
   set have;
   by ps slot;
   retain firstLat Firstlong;
   if first.slot then do;
      firstlat=lat;
      firstlong=long;
   end;
   Dist = geodist(firstlat,firstlong,lat,long);
   drop firstlat firstlong;
run;

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!

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
  • 3 replies
  • 754 views
  • 2 likes
  • 3 in conversation