I have following data set from which I am running bootstrap samples
data bio;
infile datalines delimiter=',';
input pat seq period trt Y C;
logY=log(Y);
logC=log(C);
cards;
1,1,1,1,950.59,96.3
1,1,2,2,1637.71,194
1,1,3,2,2076.75,341
1,1,4,1,1485.93,316
2,1,1,1,774.44,87.6
2,1,2,2,585.89,56.2
2,1,3,2,801.26,89.1
2,1,4,1,773.51,84.6
.
.
..
.
38,2,1,2,2252.76,304
38,2,2,1,2262.88,255
38,2,3,1,1957.66,301
38,2,4,2,3084.05,685
;
Now I am using following cods for taking bootstrap sample from above data set and it works fine for a single bootstrap sample
%let anz=19;
proc datasets nolist;
delete out1;
run;
data _boot_;
do seq=1 to 2;
do pat=(seq-1)*&anz+1 to seq*&anz;
pat_old=(seq-1)*&anz+int(&anz*ranuni(0)+1);
output;
end;
end;
run;
proc sql noprint;
create table out1 as
select _boot_.pat, bio.* from _boot_ left join bio(rename=(pat=pat_old))
on _boot_.pat_old=bio.pat_old
order by _boot_.pat, seq, pat_old, period;
quit;
Proc print data=out1;
run;
But when I want to generate multiple bootstrap sample so I have to run this code multiple times using do loop. The problem is that I don't understand where should I put do loop for multiple samples
pls guide me in this regard
Wouldn't you get the same result with SURVEYSELECT and running your subsequent analysis with BY processing? For example, three replicates of an ANCOVA:
proc surveyselect data=bio method=urs samprate=100 out=out1 outhits reps=3;
strata seq;
run;
proc sort data=out1; by Replicate seq; run;
proc glm data=out1;
by Replicate;
class seq;
model Y = seq C;
run;
PG
You might find this paper useful:
Thank you very much for your reply this article is quite informative simulation through surveyselect.
Could you please mention the error in following code for booting
Data final;
do i = 1 to &rep ;
data _boot_&rep;
do seq=1 to 2;
do pat=(seq-1)*&anz+1 to seq*&anz;
pat_old=(seq-1)*&anz+int(&anz*ranuni(0)+1);
output;
end;
end;
run;
output;
end;
stop;
I am getting error of un closed do block.
Please help
%Let rep=2;
Data final;
do i = 1 to &rep ;
data _boot_&rep;
do seq=1 to 2;
do pat=(seq-1)*&anz+1 to seq*&anz;
pat_old=(seq-1)*&anz+int(&anz*ranuni(0)+1);
output;
end;
end;
run;
output;
end;
stop;
I am getting error of un closed do block.
Please help
You can't use a "DATA" statement within another "DATA" statement. Does below amended code work for you? Make sure macro variables &rep and &anz get defined and populated before you try to execute the code.
Data final;
do i = 1 to &rep;
do seq=1 to 2;
do pat=(seq-1)*&anz+1 to seq*&anz;
pat_old=(seq-1)*&anz+int(&anz*ranuni(0)+1);
output;
end;
end;
end;
stop;
run;
Thank you very much for your reply I run this code and its work fine but I did not get desired output yet
Actually initially I am running following program
data _boot_;
do seq=1 to 2;
do pat=(seq-1)*&anz+1 to seq*&anz;
pat_old=(seq-1)*&anz+int(&anz*ranuni(0)+1);
output;
end; end; run;
proc sql noprint;
create table out1 as
select _boot_.pat, bio.* from _boot_ left join bio(rename=(pat=pat_old))
on _boot_.pat_old=bio.pat_old
order by _boot_.pat, seq, pat_old, period;
quit;
Proc print data=out1;
run;
----------------------------------------
And I am getting following output
Obs pat pat_old seq period trt Y C logY logC
1 | 1 | 19 | 1 | 1 | 1 | 1845.61 | 235.0 | 7.52057 | 5.45959 |
---|---|---|---|---|---|---|---|---|---|
2 | 1 | 19 | 1 | 2 | 2 | 2560.92 | 356.0 | 7.84812 | 5.87493 |
3 | 1 | 19 | 1 | 3 | 2 | 3088.04 | 248.0 | 8.03529 | 5.51343 |
4 | 1 | 19 | 1 | 4 | 1 | 2180.39 | 145.0 | 7.68726 | 4.97673 |
5 | 2 | 12 | 1 | 1 | 1 | 736.50 | 87.4 | 6.60191 | 4.47050 |
6 | 2 | 12 | 1 | 2 | 2 | 947.58 | 124.0 | 6.85391 | 4.82028 |
7 | 2 | 12 | 1 | 3 | 2 | 1426.96 | 151.0 | 7.26330 | 5.01728 |
8 | 2 | 12 | 1 | 4 | 1 | 681.66 | 75.5 | 6.52453 | 4.32413 |
9 | 3 | 5 | 1 | 1 | 1 | 2291.93 | 204.0 | 7.73715 | 5.31812 |
10 | 3 | 5 | 1 | 2 | 2 | 1223.74 | 126.0 | 7.10967 | 4.83628 |
11 | 3 | 5 | 1 | 3 | 2 | 1949.10 | 202.0 | 7.57512 | 5.30827 |
12 | 3 | 5 | 1 | 4 | 1 | 3184.15 | 365.0 | 8.06594 | 5.89990 |
13 | 4 | 6 | 1 | 1 | 1 | 1044.18 | 91.1 | 6.95099 | 4.51196 |
14 | 4 | 6 | 1 | 2 | 2 | 1023.00 | 111.0 | 6.93049 | 4.70953 |
15 | 4 | 6 | 1 | 3 | 2 | 1178.20 | 196.0 | 7.07174 | 5.27811 |
16 | 4 | 6 | 1 | 4 | 1 | 1155.25 | 104.0 | 7.05207 | 4.64439 |
.......................................................................
........................................................................
........................................................................
149 | 38 | 37 | 2 | 1 | 2 | 1061.92 | 97.4 | 6.96783 | 4.57883 |
---|---|---|---|---|---|---|---|---|---|
150 | 38 | 37 | 2 | 2 | 1 | 987.86 | 94.1 | 6.89554 | 4.54436 |
151 | 38 | 37 | 2 | 3 | 1 | 1422.71 | 186.0 | 7.26032 | 5.22575 |
152 | 38 | 37 | 2 | 4 | 2 | 1220.58 | 103.0 | 7.10708 | 4.63473 |
Now I want this table multiple times say 3 times so what should I add in above code pls guide
thanks in advance
Regards
How do you want multiple tables? If the exact same table repeated:
data want;
set have have have;
run;
3 identical copies.
Or if you need to identify records:
data want;
set have(in=a) have(in=b) have(in=c);
record=a*1+b*2+3*c;
run;
thank for reply actually i do not want identical copies
the above generated table is first bootstrap sample so I want multiple boot strap samples I think I have to include do loop in my code without macro
Could you please guide me
I honestly don't understand what you want. If you want more samples, why not just change the loops in your data step?
data _boot_;
do sample=1 to 10;
do seq=1 to 2;
do pat=(seq-1)*&anz+1 to seq*&anz;
pat_old=(seq-1)*&anz+int(&anz*ranuni(0)+1);
output;
end;
end;
end;
run;
Here's a tutorial on macro's from UCLA that might help you get started.
Statistical Computing Seminar: Introduction to SAS Macro Language
Hi Rasheed,
Have you tried the solution above based on SURVEYSELECT. I have used it for my own work and found it simpler and faster than alternatives based on datasteps and macro processing.
PG
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.