Thank you! I tried your solution and it works. However, I hit a problem when it's based on 3 tables. I tried the following but have problem merging the 3rd table in as it's not sorted the same way. So the function = Col3*2 + Col5 + Col7 proc sort data=table1 out= table1;
by col1;
run;
proc sort data=table1 out= table1_1;
by col2;
run;
%let num=10; /* number of simulations */
/* Prepare lookup table of random numbers for ABCD */
data rand_list1;
call streaminit(27182818);
retain i;
set table1(keep=col1);
by col1;
if first.col1;
do i=1 to #
rv1=rand('uniform');
output;
end;
run;
/* Prepare lookup table of random numbers for XYZ */
data rand_list1;
call streaminit(42);
retain j;
set table1(keep=col2);
by col2;
if first.col2;
do j=1 to #
rv2=rand('uniform');
output;
end;
run;
proc sort data=rand_list1;
by i;
run;
proc sort data=rand_list2;
by j;
run;
/* Replicate dataset TABLE1 to have &num copies */
proc surveyselect data=table1 noprint
out=monte_carlo1(rename=(replicate=i))
rep=&num samprate=1;
run;
/* Replicate dataset TABLE1_1 to have &num copies */
proc surveyselect data=table1_1 noprint
out=monte_carlo2(rename=(replicate=j))
rep=&num samprate=1;
run;
/* Simulate function */
data monte_carlo1;
merge monte_carlo1
rand_list1;
by i col1;
run;
data monte_carlo2;
merge monte_carlo2
rand_list2;
by j col2;
run;
I reckon I need to sort and merge the 2 tables, however, i and j are not common. How should I proceed? Also Table1 is 15k records and I plan to simulate 100k trials. This seems to get really big. Many thanks again.
... View more