It would have been useful for you to have posted your code.
Because you are storing character values, you can't allocate a numerical matrix of zeros. Instead you need to allocate a character matrix of blank strings. See the article "How to create a string of a specified length" for tips about how to create a matrix that contains a matrix that contains all blank strings. Then inside the loop you look at the number of elements of each sample and assign it to columns 1:3 or 1:4 of the i_th row, as follows:
proc iml;
call randseed(1234);
list = {peter piper picked a peck of pickled peppers};
N = 10;
/* determine number of items */
numItems = sample({3 4}, N);
print numItems;
/* Allocate matrix for results. See
http://blogs.sas.com/content/iml/2014/05/12/how-to-create-a-string-of-a-specified-length-in-sasiml.html */
results = j(N, 4, BlankStr(nleng(list)));
do i = 1 to N;
items = sample(list, numItems[i]);
results[i, 1:ncol(items)] = items;
end;
print results;