Random sas中的随机数生成和两个DO…END循环
我需要使用SAS随机数生成函数Random sas中的随机数生成和两个DO…END循环,random,sas,Random,Sas,我需要使用SAS随机数生成函数RAND()和DO…END循环在名为X的变量中创建100个OB,然后我想使用另一个500轮的DO循环生成总共500个样本,每个样本有100个OB。样本基本上是从标准正态分布中取样 我尝试了以下代码,但它没有提供我需要的: data A; call streaminit(123); /* set random number seed */ do i = 1 to 100; X = rand("Normal"); /* random number gener
RAND()
和DO…END循环
在名为X的变量中创建100个OB,然后我想使用另一个500轮的DO循环生成总共500个样本,每个样本有100个OB。样本基本上是从标准正态分布中取样
我尝试了以下代码,但它没有提供我需要的:
data A;
call streaminit(123); /* set random number seed */
do i = 1 to 100;
X = rand("Normal"); /* random number generator */
output;
end;
do r = 1 to 500 ;
if i then X = rand("Normal");
output;
end;
run;
如有任何意见,我们将不胜感激。使用PROC IML的最佳时机:
proc iml;
call streaminit(123); /* set seed */
x = j(500, 100); /* allocate 500 by 100 matrix */
call randgen(x, "Normal"); /* fill matrix with N(0,1) random draws */
create mydata from x; /* move matrix to a dataset in the work directory */
append from x;
close mydata;
quit;
使用PROC IML的最佳时机:
proc iml;
call streaminit(123); /* set seed */
x = j(500, 100); /* allocate 500 by 100 matrix */
call randgen(x, "Normal"); /* fill matrix with N(0,1) random draws */
create mydata from x; /* move matrix to a dataset in the work directory */
append from x;
close mydata;
quit;
下面是一个数据步解决方案
data want;
do I=1 to 500;
do _iorc_=1 to 100;
X=rand ("normal");
output;
end;
end;
run;
下面是一个数据步解决方案
data want;
do I=1 to 500;
do _iorc_=1 to 100;
X=rand ("normal");
output;
end;
end;
run;
听起来像是要将一个do循环嵌套在另一个do循环中。是要将500行100个变量(
x1
到x100
)还是50000行round
,sample
,X
)听起来像是要将一个do循环嵌套在另一个do循环中。是要将500行100个变量嵌套在另一个do循环中吗(x1
至x100
)或者50000行的round
,sample
,X
?非常感谢。但是\u iorc\u
的意义是什么?当然可以。iorc只是一个自动删除的自动变量。我也可以用I代替iorc,但是我必须再次删除它。非常感谢。的意义是什么>_iorc当然可以。iorc只是一个自动删除的自动变量。我也可以用I来代替iorc,但是我必须再次删除它。