BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Sanscrit_2prov
Obsidian | Level 7

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
ardehg
SAS Employee

please replace {val} with val. Your ListSetItem call should look like:

call ListSetItem (nz2enum,i,val);

 

View solution in original post

4 REPLIES 4
ardehg
SAS Employee

please replace {val} with val. Your ListSetItem call should look like:

call ListSetItem (nz2enum,i,val);

 

Sanscrit_2prov
Obsidian | Level 7

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!

ardehg
SAS Employee

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.

Sanscrit_2prov
Obsidian | Level 7

Thank you so much. This is exactly what I need and I did not know the IML coding that you sent. Again, many thanks.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 4 replies
  • 1022 views
  • 1 like
  • 2 in conversation