BookmarkSubscribeRSS Feed
brophymj
Quartz | Level 8

I want to be able to simulate 8 random xy coordinates (limiting the max x and y to 1000 each and only allowing integers) and then be able to do the following:

Calculate all the distances between all the points. For 8 points there will be n(n-1)/2 distances so 28 distances. I want to calculate the mean and standard deviation of the distances.

Calculate the length of every possible route consisting of a path between one of the points (called the start point) and every other point returning to the original point (travelling salesman like situation) and work out the minimum distance.

Calculate the distance from the start point to the furthest point from the start point

Calculate the distance of the perimeter that consists of the outer points of the shape

I know there is a lot here but I'm trying to start off by simulating 8 random numbers. The code below simulates 26 coordinates and the calculates the distance between every point but I want the points to be random.

data Obs;
do x=0 to 5;
   do y=0 to 5;
         output;
   end;
end;
run;

proc distance data=Obs out=Dist method=Euclid nostd;
   var interval(x y);
run;

Thanks

5 REPLIES 5
ballardw
Super User

You say 8 random numbers but generate 36?

This will generate random points. Change I get the number of pairs you want.

data obs;

   do i= 1 to 36;

      x= round(1000* ranuni(123),1);

      y= round(1000* ranuni(789),1);

      output;

   end;

run;

good luck with the rest.

Reeza
Super User

Once you have your simulated data you can do a cross join and then you can do your stats.

Building on @ballardw code

data obs;

   do i= 1 to 8;

      x= round(1000* ranuni(123),1);

      y= round(1000* ranuni(789),1);

      output;

   end;

run;

proc sql;

create table xdistance as

select a.x as x1, a.y as y1,

b.x as x2, b.y as y2

from obs as a

cross join obs as b

where a.i<b.i;

quit;

brophymj
Quartz | Level 8

Thanks Reeza

If I chose a START vector, say 750,321 would I need to use arrays to create a table with 18 fields (x1 y1 x2 y2 ... x8 y8 x1y1) which showed every combination of the 8 coordinates conditional on the first number being 750,321. I would then create 19/20th fields with 750,321 in every row. I'm trying to simulate a situation where each coordinate represents a city (so 8 cities) and I want to work out the quickest route if you were to start at 750,321 and visit all cities before returning to 750,321. There are (n-1)!/2 possible routs so 2520.

Once I have my table in the above format I will calculate the total distance travelled for each of the 2520 possible routes. The smallest one will be the optimal route.

Reeza
Super User

You could use arrays...

SAS OPTGRAPH is designed exactly for this type of analysis.

SAS(R) OPTGRAPH Procedure 14.1: Graph Algorithms and Network Analysis

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 1519 views
  • 0 likes
  • 3 in conversation