Hi
I am working in SAS/IML
I have generated multiple matrices, each of single row and two column using do loop
now I want to convert all the matrices in a single data set with only variables and number of observation would definitely be equal to number of iterations
Kindly help me
following is the part of matrices output
i I_ij
1 -17.98802 11.706846
i I_ij
2 -16.85767 12.894326
i I_ij
3 -18.33006 11.883216
If you are wanting to create a SAS dataset with the results, then look in to the CREATE and APPEND statements. For example:
I_ij = j(1,2);
create mydata from I_ij;
do i=1 to 10;
call randgen(I_ij, 'uniform');
append from I_ij;
end;
close mydata;
Thank you very much
in your example, you create a matrix then draw sample matrices through uniform dist. and then create data set for all drawn sample
but in my case i dont want to draw samples, however i have multiples matrices now my objective is to create a data set involving all matrices,
for this purpose,during my search, I found following example, which is not exactly what I want, but may be useful
Proc iml;
PCOR = {1.00 0.40 0.40,
0.40 1.00 0.40,
0.40 0.40 1.00};
dsNames = {A B C};
print dsNames;
do i = 1 to ncol(dsNames);
pvar = diag(vecdiag(pcor))*i;
create(dsNames) from pvar;
append from pvar;
close (dsNames);
end; */;
The problem with example is that when I run this there is an error in create(dsNames) and close (dsNames)
Pls guide
Thanks
The code you posted works for me. I am running SAS 9.4 (IML 13.1) and it is possible you have an old version without this feature.
I think there may be a way around with call execute. Try replacing the create and close statements with something like:
call execute('create ' + dsNames + ' from pvar;');
call execute('close ' + dsNames + ';' );
This will only work if the code is inside a module.
Thanks
yes i am using sas 9.02 version
I think version is matter here
can u share me sas 9.04 software backup through dropbox
I would be really grateful to you
Regards
Dear Ian Wakeling
I would really be grateful to you if you could share me SAS 9.4 version backup
Regards
No, I can't do that. You need to talk to someone at your nearest SAS office about an upgrade. Or perhaps investigate the SAS University Edition.
I got SAS 9.3
Now try to run following program
Proc iml;
PCOR = {1.00 0.40 0.40,
0.40 1.00 0.40,
0.40 0.40 1.00};
dsNames = {A B C}; /* specify names of data sets */
do i = 1 to ncol(dsNames);
pvar = diag(vecdiag(pcor))*i;
create(dsNames) from pvar; /* create work.A, then work.B, and so on */
append from pvar;
close (dsNames);
end;
But it is not working gives few errors
Log is as follows
NOTE: IML Ready
5088 PCOR = {1.00 0.40 0.40,
5089 0.40 1.00 0.40,
5090 0.40 0.40 1.00};
5091 dsNames = {A B C};
5091! /* specify names of data sets */
5092 do i = 1 to ncol(dsNames);
5093 pvar = diag(vecdiag(pcor))*i;
5094 create(dsNames) from pvar;
-
22
76
ERROR 22-322: Expecting a name.
ERROR 76-322: Syntax error, statement will be ignored.
5095 append from pvar;
5096 close (dsNames);
-
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.
5097 end;
ERROR: END does not occur within DO group at line=5097 col=1.
Kindly help me
This is the same error as before, so the ability to specify the dataset name from a character matrix must be a more recent innovation. Try this instead:
Proc iml;
start main;
PCOR = {1.00 0.40 0.40,
0.40 1.00 0.40,
0.40 0.40 1.00};
dsNames = {A B C}; /* specify names of data sets */
do i = 1 to ncol(dsNames);
pvar = diag(vecdiag(pcor))*i;
call execute('create ' + dsNames + ' from pvar;');
append from pvar;
call execute('close ' + dsNames + ';' );
end;
finish;
run main;
quit;
Same answer as before: YOu need SAS 9.3m2 or later (SAS/IML 12.1): Read data sets that are specified by an array of names - The DO Loop
What do you intend to do with the output data? In my experience, one data set with k observations is almost always easier to work with than k data sets with one observation in each. The ideas in this blog post might be relevant: Simulation in SAS: The slow way or the BY way
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.