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

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

11-10-2015 05:21 AM

Hi everybody,

I hope this message finds you well.

I have a matrix, let's say MAT, and I would like to make the product of the elements on each row and output the resulting vector in VEC.

So VEC i = product MAT[ i , 1:NCOL(MAT)].

I simply figured it out using a do loop as follows:

do i = 1 to nrow(MAT);

do r = 1 to ncol(MAT);

VEC [ i ,1]=VEC [i,1]*MAT[i,r];

end;

end;

But it takes too much time to run the above instructions since I have to run the same instructions 300,000 times (in different scenarios).

Do you have any better idea to optimize the runtime?

Thanks a lot in advance.

Raphaël

Accepted Solutions

Solution

11-10-2015
11:33 AM

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

Posted in reply to NewbieRaph

11-10-2015 07:57 AM

`vec = mat[ , #];`

SAS/IML supports many elementwise operations. Two articles you might want to read are:

"Use subscript reduction operators"

and

"Compute statistics for each row by using subscript operators"

All Replies

Solution

11-10-2015
11:33 AM

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

Posted in reply to NewbieRaph

11-10-2015 07:57 AM

`vec = mat[ , #];`

SAS/IML supports many elementwise operations. Two articles you might want to read are:

"Use subscript reduction operators"

and

"Compute statistics for each row by using subscript operators"

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

Posted in reply to Rick_SAS

11-10-2015 09:21 AM - edited 11-10-2015 09:24 AM

Thanks Rick! :-)

It works perfectly and is 60 seconds faster for 20 scenarios.

You are my savior!

I notice that you already posted it 3 years ago in your second link...

Raphael

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

Posted in reply to NewbieRaph

11-10-2015 10:29 AM

Great. Remember to click the "Accept as Solution" button so that others can see that the question has been answered.

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

Posted in reply to Rick_SAS

11-10-2015 11:33 AM

Done!!

Raphaël