BookmarkSubscribeRSS Feed
fayyazcivil
Calcite | Level 5

Hello.

I've a matrix of order 61312*3.

1st column represent Origin (from 1 to 81)

2nd column represent Destination (from 1 to 81)

3rd column represent location of survey (1 to 246)

I need a matrix of 3 columns (but rows can increased now instead of 61312), of below type;

Origin Destination Location

1             1                   1

1                2                2 or can be none

1                .                     .

1                81                  246

2                1                     1

.                        .                     .

81                81                     246

Kindly, let me know how should I proceed.

8 REPLIES 8
fayyazcivil
Calcite | Level 5

Thank you very much for this.

I am very new to SAS. I don't know what is SAS/IML, I am using SAS 9.4.

Kindly let me know how can I switch to SAS/IML? or it's a different software?

Ksharp
Super User

Yeah. That is a different language designed special for Matrix .

You didn't need to switch it , you run it as data step did, if you already have SAS/IML .

fayyazcivil
Calcite | Level 5

OK, thanks for this.

Let me find SAS/IML software first, and then will run it.

Rick_SAS
SAS Super FREQ

You need to explain the data better.  81*81 = 6561, so where is the number 61312 coming from? Do you have duplicates in the (origin, destination) ordered pairs?

I initially thought that you wanted to put the locations into an 81x81 matrix.  That is easy in SAS/IML---although you did not post to that forum, so perhaps you are seeking a DATA step solution?  If so, maybe create the full 81x81 data set and merge with a sorted version of your data?

Here is a solution in PROC IML to packing this data into an array. Perhaps others can build on it or it can be used to better understand what you want and do not want:

data Have;
input origin destination location;
datalines;
1             1                   1
1             2                   2
1            81                 246
2             1                   1
81           81                 246
;

proc iml;
use Have;
read all var {origin destination location};
close Have;

A = j(81,81,.);      /* use missing values */
idx = sub2ndx(dimension(A), origin || destination);
A[idx] = location;  /* put specified locations in 81x81 matrix */ 

/* create full set of subscripts and write data */
grid = expandgrid(1:81, 1:81);
origin = grid[,1];
destination = grid[,2];
location = A;    /* rename */


create Want var {origin destination location};
append;
close Want;

fayyazcivil
Calcite | Level 5

Dear Rick,

Thanks for your reply.

Yes I've duplication in the data i.e. origin destination pairs, which are 61312 instead of (81*81)=6561.

But for this case rows should be 81*81*246=1614006 (because 246 are the number of locations where survey conducted)

It will be like 4 columns: Origin, Destination, Survey_Locations(246),  Interception_Pt(1 if intercepted or 0 otherwise)

I am going to install SAS/IML in a few days, and will read first the "Getting Started with the SAS/IML Matrix Programming Language", then I will come back to you, via SAS/IML forum.


Thanks.

fayyazcivil
Calcite | Level 5

The sequence will be like this:

Origin (1)  Destination(1)  Survey_Location(1)  Interception_Pt (0 or 1)

Origin (1)  Destination(1)  Survey_Location(2)  Interception_Pt (0 or 1)

.......

Origin (1)  Destination(1)  Survey_Location(246)  Interception_Pt (0 or 1)

Origin (1)  Destination(2)  Survey_Location(1)   Interception_Pt (0 or 1)

......

Origin (2)  Destination(1)  Survey_Location(1)  Interception_Pt (0 or 1)

.........

Origin (81)  Destination(81)  Survey_Location(246)  Interception_Pt (0 or 1)

For this case rows should be 81*81*246=1614006

Tom
Super User Tom
Super User

What are you trying to do with the data?  Are you sure that thinking about it as if it was a matrix is helpful in getting that done?

Almost any data set can be thought of as one or more arrays.  For example you have N variables of which D are used as key variables and M are results or measures such that N=D+M. Then this data set could be thought as a series of M arrays of D dimensions.  Of if the measures are all of the same type then a (D+1) dimensional array where the last dimension specifies the measure.

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!

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
  • 8 replies
  • 1086 views
  • 6 likes
  • 4 in conversation