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
- /
- SAS Programming
- /
- Base SAS Programming
- /
- Matrix or Array Arrangement

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
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-06-2014 06:02 AM

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.

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

Posted in reply to fayyazcivil

07-06-2014 07:26 AM

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

Posted in reply to Ksharp

07-06-2014 07:58 AM

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?

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

Posted in reply to fayyazcivil

07-06-2014 08:06 AM

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 .

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

Posted in reply to Ksharp

07-06-2014 08:10 AM

OK, thanks for this.

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

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

Posted in reply to fayyazcivil

07-06-2014 08:17 AM

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;

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

Posted in reply to Rick_SAS

07-06-2014 09:56 AM

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.

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

Posted in reply to Rick_SAS

07-06-2014 10:16 AM

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

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

Posted in reply to fayyazcivil

07-06-2014 11:11 AM

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.