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.
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 */
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.
See this article on how to remove rows that have a missing values in any variable:
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.