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);
please replace {val} with val. Your ListSetItem call should look like:
call ListSetItem (nz2enum,i,val);
please replace {val} with val. Your ListSetItem call should look like:
call ListSetItem (nz2enum,i,val);
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!
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;
Please let me know if I still don't understand your question.
Thank you so much. This is exactly what I need and I did not know the IML coding that you sent. Again, many thanks.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.