如何在SAS/IML中使用do循环创建多个数据集?

如何在SAS/IML中使用do循环创建多个数据集?,sas,sas-iml,Sas,Sas Iml,我尝试了以下代码: proc IML; do i=1 to 20; [some codes to execute] data[i]; end; QUIT; 因此,我希望在完成do循环后获得20个数据集。在SAS中是否可以执行此操作?我可以使用宏来完成,但我不喜欢在PROC IML中使用宏 提前感谢。是的,使用模块内部的调用执行子例程 proc iml; file LOG; output = (1:10)`; /*This is how you create a data s

我尝试了以下代码:

proc IML;
do i=1 to 20;  
[some codes to execute]  
data[i];  
end;  
QUIT;
因此,我希望在完成do循环后获得20个数据集。在SAS中是否可以执行此操作?我可以使用宏来完成,但我不喜欢在
PROC IML
中使用宏


提前感谢。

是的,使用模块内部的
调用执行
子例程

proc iml;
file LOG;

output = (1:10)`;

/*This is how you create a data set from a matrix*/
create outdata from output;
append from output;
close outdata;

/*This module will create 1 data set for each variable in OUTPUT*/
start loopit;
do i=1 to 10;
    x = output[i];
    /*build the string you want to execute*/
    outStr = 'create outdata' + catt(i) + " from x; append from x; close outdata" + catt(i) + ";";
    put outStr; /*Print the string to the log*/

    /*Execute the string*/
    call execute(outStr);
end;
finish loopit;

/*Call the module*/
call loopit;

quit;

如果您有SAS/IML 12.1,它作为SAS 9.3m2的一部分于2012年8月发布,那么您可以将每个数据集的名称用括号括起来,如下所示

proc iml;
names = "Data1":"Data20";
do i = 1 to ncol(names);
   x = i;
   dsname = names[i];   /* construct each name */
   create (dsname) from x;
   append from x;
   close (dsname);
end;

有关完整的程序和说明,请参阅文章中的最后一个示例

非常感谢@Rick。我使用了
dsname={}
然后我得到了20个数据集,命名为data1、data2等等。当我重新运行代码时,它再次从21开始生成20个数据集,即data21、data22等等。有什么方法可以设置我的首选名称吗?还有,在重新运行代码的情况下,是否有任何方法可以覆盖数据集?DSName需要是标量。我对程序进行了编辑,使其更清晰。Awesome@Rick. 我很感激。