turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- Analytics
- /
- Stat Procs
- /
- Similating coordinates and calculating various fun...

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-19-2015 10:57 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to brophymj

08-19-2015 11:10 AM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to brophymj

08-19-2015 11:16 AM

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;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Reeza

08-19-2015 03:52 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to brophymj

08-19-2015 04:02 PM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to brophymj

08-19-2015 04:18 PM