Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SAS Multi-dimension Array

Status
Not open for further replies.

mzhang

MIS
Apr 17, 2003
1
US
This might be a little challenging ...

1) I need to load a 4 x 3 (row x column) m-array in an array. --- Is this doable?

2) If the data are points on a plane, I need to calculate distance between any two point of the plane. For example:

A 1 2
B 3 4
C 5 6
D 7 8

I Need to calc distance between: A-B, A-C, A-D, B-C, B-D, C-D. Is there a good way to do it in SAS?

Thank you so much ...
 
I would do this one way --- others would do it another (probably the PLI / C background - sorry) -- you could do things like variably determine the size of the array, but this should get you a start;

Data Points;
INFILE *youdefinethis*;
Retain ArrayElem;
ARRAY PointName{10}; <== DEFINE SIZE OF ARRAY
ARRAY PointXCoord(10);
Array PointYCoord(10);
INPUT @1 Point $CHAR1.
@3 PointX,
@5 PointY ;
If _n_ =1 /* first record */
Then ArrayElem = 0;
ArrayElem = ArrayElem + 1;
PointName{ArrayElem} = Point;
PointXCoord{ArrayElem} = PointX;
PointYCoord{ArrayElem} = PointY;

Data Distance;
Set Points;
ARRAY PointName{10};
ARRAY PointXCoord(10);
Array PointYCoord(10);

Do I = 1 to Dim(PointName);
Do J = I+1 to Dim(PointName);
From = 'From' || PointName{I} || ' To ' || PointName{J};
Distance = PointXCoord{I}... /*insert desirect formula here */
Keep From Distance;
Output;
End;
End;


My plane geometry is a bit rusty so you will need to do the math, but this should give you an output file with two variables (the label & the distance).

Make sense?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top