BookmarkSubscribeRSS Feed
Bogdan
Calcite | Level 5

I might create a matrix through a process, but I don't know its dimension beforehand. As far as I know, you can't define a matrix with some temporarily open size, right?

If so, what are some ideas to adjust for this issue?

One way is to define a matrix with sufficiently big size. Then afterwards trim by missing values or reduce the size based on some counter. For example, if you work out a matrix from other one, you allow the size based on the original matrix.

3 REPLIES 3
Rick_SAS
SAS Super FREQ

Right. An example of this situation is in this article:  Efficient acceptance-rejection simulation - The DO Loop

Some people append to a matrix within a loop (see Pre-allocate arrays to improve efficiency - The DO Loop), but that is inefficient so I try to allocate the matrix as large as it might be, and then fill only the rows that are actually used. As you say, trim the rest, like this:

x = j(100, 1, .); /* use missing values to mark unused rows */

do i = 1 to 10;

/* do something that fills 85% of the rows */

end;

x = remove(x, loc(x=.));  /* remove and missing values */

Bogdan
Calcite | Level 5

About your program mr. Wicklin, how can you remove rows based on the missing values occurring in a column?

The program you showed works for vectors, i.e. matrices of dimension  n x 1.

Rick_SAS
SAS Super FREQ

See this article on how to remove rows that have a missing values in any variable:

Count missing values in observations - The DO Loop

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 3 replies
  • 981 views
  • 6 likes
  • 2 in conversation