Thanks for your advice, but can you check this out? This is your version. proc iml;
/* Use Sashelp.Air for example */
use Sashelp.Air;
read all var 'Air' into a;
close;
t=nrow(a);
call streaminit(1);
/* allocate and tell output data set how many cols to expect */
bootstrap = j(t,1,.) || a;
create bootstrap from bootstrap[c={"SampleID" "a"}];
v = j(t,1,.);
do b=1 to 2500;
/*----------------------------the bottleneck parts----------------------------*/
do u=1 to t;
if u=1 then v[u]=rand("integer",1,t);
else if v[u-1]=t then v[u]=rand("integer",1,t);
else if rand("uniform")>0.9 then v[u]=rand("integer",1,t);
else v[u]=v[u-1]+1;
end;
bootstrap = j(t,1,b) || a[v,];
/*----------------------------------------------------------------------------*/
append from bootstrap;
end;
close;
quit; Here is the log. 1 proc iml;
NOTE: IML Ready
2 /* Use Sashelp.Air for example */
3 use Sashelp.Air;
4 read all var 'Air' into a;
5 close;
NOTE: Closing SASHELP.AIR
6 t=nrow(a);
7 call streaminit(1);
8
9 /* allocate and tell output data set how many cols to expect */
10 bootstrap = j(t,1,.) || a;
11 create bootstrap from bootstrap[c={"SampleID" "a"}];
12
13 v = j(t,1,.);
14 do b=1 to 2500;
15 /*----------------------------the bottleneck parts----------------------------*/
16 do u=1 to t;
17 if u=1 then v[u]=rand("integer",1,t);
18 else if v[u-1]=t then v[u]=rand("integer",1,t);
19 else if rand("uniform")>0.9 then v[u]=rand("integer",1,t);
20 else v[u]=v[u-1]+1;
21 end;
22 bootstrap = j(t,1,b) || a[v,];
23 /*----------------------------------------------------------------------------*/
24 append from bootstrap;
25 end;
26 close;
NOTE: Closing WORK.BOOTSTRAP
NOTE: The data set WORK.BOOTSTRAP has 360000 observations and 2 variables.
27 quit;
NOTE: Exiting IML.
NOTE: PROCEDURE IML used (Total process time):
real time 1.18 seconds
cpu time 1.17 seconds And the following does not pre-allocate. proc iml;
/* Use Sashelp.Air for example */
use Sashelp.Air;
read all var 'Air' into a;
close;
t=nrow(a);
call streaminit(1);
/* allocate and tell output data set how many cols to expect */
bootstrap = j(t,1,.) || a;
create bootstrap from bootstrap[c={"SampleID" "a"}];
/* v = j(t,1,.);*/
do b=1 to 2500;
/*----------------------------the bottleneck parts----------------------------*/
do u=1 to t;
if u=1 then v=rand("integer",1,t);
else if v[u-1]=t then v=v//rand("integer",1,t);
else if rand("uniform")>0.9 then v=v//rand("integer",1,t);
else v=v//v[u-1]+1;
end;
bootstrap = j(t,1,b) || a[v,];
/*----------------------------------------------------------------------------*/
append from bootstrap;
end;
close;
quit; And the log. 28 proc iml;
NOTE: IML Ready
29 /* Use Sashelp.Air for example */
30 use Sashelp.Air;
31 read all var 'Air' into a;
32 close;
NOTE: Closing SASHELP.AIR
33 t=nrow(a);
34 call streaminit(1);
35
36 /* allocate and tell output data set how many cols to expect */
37 bootstrap = j(t,1,.) || a;
38 create bootstrap from bootstrap[c={"SampleID" "a"}];
39
40 /* v = j(t,1,.);*/
41 do b=1 to 2500;
42 /*----------------------------the bottleneck parts----------------------------*/
43 do u=1 to t;
44 if u=1 then v=rand("integer",1,t);
45 else if v[u-1]=t then v=v//rand("integer",1,t);
46 else if rand("uniform")>0.9 then v=v//rand("integer",1,t);
47 else v=v//v[u-1]+1;
48 end;
49 bootstrap = j(t,1,b) || a[v,];
50 /*----------------------------------------------------------------------------*/
51 append from bootstrap;
52 end;
53 close;
NOTE: Closing WORK.BOOTSTRAP
NOTE: The data set WORK.BOOTSTRAP has 360000 observations and 2 variables.
54 quit;
NOTE: Exiting IML.
NOTE: PROCEDURE IML used (Total process time):
real time 1.17 seconds
cpu time 1.17 seconds It seems there is no performance difference—I also tried 25,000 rather than 2,500 but found no difference.
... View more