## Convert Matlab Code to IML List Matrix

Hello:

I'm trying to convert the following matlab code to sas iml.

do=1 to maxzeros;

matrixname[i]=0:(2^-i)-1;

end;

matrixname is a cell matrix, which corresponds to a list matrix in SAS IML.   The operator ^ raises 2 to a power.

So let's say the index (i)=3. Then this code creates a matrix cell with 8 values 0,1,2,3,4,5,6,7.

I've written the following in IML so far:

nz2enum=listcreate(maxnonzeros);
do i=1 to maxnonzeros;
max=(2 ## i);
do k=1 to max;
val=k-1;
call ListSetItem (nz2enum,i,{val});    This inserts the word val. How to get it to insert the number val?
end;
end;
run listprint (nz2enum);

1 ACCEPTED SOLUTION

Accepted Solutions

## Re: Convert Matlab Code to IML List Matrix

``call ListSetItem (nz2enum,i,val);``

4 REPLIES 4

## Re: Convert Matlab Code to IML List Matrix

``call ListSetItem (nz2enum,i,val);``

## Re: Convert Matlab Code to IML List Matrix

Thank you now that works. The only problem is I need a way to place val is separate columns of the list. Is there a form of the list set item command where you can reference the individual cells in the list?  That is, I want to place 0,1,2,3,4,5,6,7 as separate columns in the list.

Thanks you very much!

## Re: Convert Matlab Code to IML List Matrix

If I understand your question correctly (and based on looking at your Matlab code) you may be looking for the following:

``````proc iml;
maxnonzeros = 3;
nz2enum=listcreate(maxnonzeros);
do i=1 to maxnonzeros;
val = 0:(2##i-1);
call ListSetItem (nz2enum,i,val);
print (nz2enum\$i);
end;
``````