Turn on suggestions

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

Showing results for

Options

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

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 04-02-2014 07:58 AM
(2657 views)

Dear all,

I would like to find an efficient way do delete zero column.

(part of my simulation results are matrix with zero columns

so I can't invert the matrix and it ends with empty value).

for example:

C={1 1 0 0 0,

1 0 0 1 0,

1 0 0 1 0}

I want to get:

D={1 1 0,

1 0 1,

1 0 1}

Thank you,

Orit

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

You must have misunderstood my suggestion. You use S to find and extract the rows of the original matrix:

S = (C^=0);

cols = loc(S[+, ]>0);

if ncol(cols)>0 then

D = C[,cols];

else

D = C;

7 REPLIES 7

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Are your matrix elements always binary 0/1? If so, just sum down the columns and keep the colums that sum to any positive value:

cols = loc(C[+, ]>0);

if ncol(cols)>0 then

D = C[,cols];

else

D = C;

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Thank you Rick!

But No, my matrix contains positive and negative number in their columns.

Like

C={5 6 0 0 0,

-5 0 0 -8 0,

0 0 0 7 0}

How do you recommend do solve that ?

Thanks,

Orit

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Define

S = (C^=0);

S is a binary 0/1 matrix, so use the previous code I sent.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

That is elegant,thanks!

The only problem is, that you end this code with the **binary matrix**.

I need the** original matrix** because I use it for other computations.(for ols coefficients)

How do you recommend to do that?

Thanks,

Orit

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

You must have misunderstood my suggestion. You use S to find and extract the rows of the original matrix:

S = (C^=0);

cols = loc(S[+, ]>0);

if ncol(cols)>0 then

D = C[,cols];

else

D = C;

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Thank you Rick!!

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Please check this works for you:

x=(C^=0);

Cnew=C[,loc(x[+,]^=0)];

Are you ready for the spotlight? We're accepting content ideas for **SAS Innovate 2025** to be held May 6-9 in Orlando, FL. The call is **open **until September 25. Read more here about **why** you should contribute and **what is in it** for you!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.