Ok I try
I would be grateful if you could pleas tell how could I save each matrix in different variable I am using following program
r = 1:2; /* row numbers to extract from x */
do boot = 1 to 2;
y = x[r, 2:3];
< do stuff here with the 2x2 matrix y >
r = r + 2; /* increment row numbers for next boot */
end;
Plz help me in this regard
If you are prepared to sacrifice readability of code, then you can create a character matrix y that contains the names of each matrix in your list. Then you can use the VALUE() function and the VALSET() call every time you want to refer to those matrices.
x = {
1 0.0036813 0.0030405 ,
1 0.0030405 0.0032935 ,
2 0.0015928 0.0017098 ,
2 0.0017098 0.0020805 };
y = 'y_1' : 'y_2'; /* define matrix NAMES */
r = 1:2;
do k = 1 to 2;
call valset( y
print (value( y
call valset( y
print (value( y
r = r + 2;
end;
I can see Rick's point that it will be easier to store all the results in once place, however I would prefer to have a choice and for there to be an easier way to create a list of matrices, where each element can be a matrix of any size.
Thanks Ian I used your code it worked fine for me thank you again Now one thing is more I want to convert these separated matrices into separate data sets and using following command but not working pls guide. Here I want to convert matrices C_1, C_2 into data sets CD_1 CD_2
do k = 1 to 2;
call execute('create ' + CD
append from value(C
call execute('close ' + CD
end;
In this context (CREATE and APPEND), you do not want the value of the matrix, just its name. So you would need to modify the code as follows:
do k = 1 to 2;
call execute('create ' + CD
call execute('append from ' + C
call execute('close ' + CD
end;
and because of the call execute, you would have to use this code within a module. Be warned this could get messy if you are creating hundreds of data sets, why not save the original matrix from the beginning of this thread as a SAS data set?
Thanks again Ian, is there any option from which we can convert into data sets without using module?
You would have to copy your matrix C
do k = 1 to 2;
z = value(C
create (CD
append from z ;
close (CD
end;
When I run the above previous code I got the following error
do k = 1 to 2;
891
892 z = value(C
893
894 create (CD
-
22
76
ERROR 22-322: Expecting a name.
ERROR 76-322: Syntax error, statement will be ignored.
895
896 append from z ;
897
898 close (CD
-
22
200
ERROR 22-322: Syntax error, expecting one of the following: a name, ;.
ERROR 200-322: The symbol is not recognized and will be ignored.
899
900 end;
ERROR: END does not occur within DO group at line=900 col=3.
I presume you have CD defined with something like:
CD='CD_1':'CD_2';
In which case it might be a version thing as it is working for me in SAS/IML 13.1. Perhaps Rick could confirm this, and also comment on why an expression was allowed for the data set name, but not for the matrix name.
There are two matrices C_1 and C_2 and I am using following code without module to convert them in to data sets CD_1 and CD_2
CD='CD_1':'CD_2';
do k = 1 to 2;
z = value(C
create (CD
append from z ;
close (CD
end;
But still got the same error
Reading and writing data sets whose names are contained in a character matrix is supported beginning in SAS/IML 12.1 (released with 9.3m2). See http://blogs.sas.com/content/iml/2013/07/29/read-data-sets-array-names.html
Ian: The APPEND statement doesn't support expressions because it is valid syntax to specify a character matrix, in which case the APPEND statement writes that data to the data set.
If you wish to pursue Ian's suggestion, there is more information about VALUE and VALSET in the article "Indirect assignment: How to create and use matrices named x1, x2,..., xn"
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.