|
|
沙发

楼主 |
发表于 2008-3-22 02:37:23
|
只看该作者
Re: 请教有关SAS产生随机数的问题
This approach is nasty but it gets the job done. I have a hard time to find other ways to do it, someone else here could have a better idea. Hope this helps and good luck.
/* Get all combinations between a and b */
proc iml;
a={1 2 3 4 5 6 7 8 9 10 };
b={11 12 13 14 15 16 17 18 19 20};
allcomb = j(100,2,1);
do i=1 to 10;
ai=a[1,i];
do j=1 to 10;
aj=b[1,j];
allcomb[10*(i-1)+j,1]=ai;
allcomb[10*(i-1)+j,2]=aj;
end;
end;
create comb from allcomb[colname={'a' 'b'}];
append from allcomb;
quit;
/* Randomly sample the combinaion 1000 times with replacement */
proc surveyselect data=comb method = urs sampsize = 1000
rep=1 seed=12345 out=sampling;
id a b;
run;
/* Output the completed dataset */
data allsamples;
set sampling;
do i = 1 to numberhits;
output;
end;
drop i numberhits;
run;
/* calculate Y */
data yvalue;
set allsamples;
Y = a**2 + b**3 ;
run;
ods html;
ods graphics on;
proc univariate data=yvalue plot;
var y;
run;
ods graphics off;
ods html close; |
|