BookmarkSubscribeRSS Feed
Rasheed
Calcite | Level 5

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

                                                                                                                                                                                                                                       

10 REPLIES 10
PGStats
Opal | Level 21

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

PG
Reeza
Super User
Rasheed
Calcite | Level 5

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

Rasheed
Calcite | Level 5

%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

Patrick
Opal | Level 21

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;

Rasheed
Calcite | Level 5

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

11191111845.61235.07.520575.45959
21191222560.92356.07.848125.87493
31191323088.04248.08.035295.51343
41191412180.39145.07.687264.97673
5212111736.5087.46.601914.47050
6212122947.58124.06.853914.82028
72121321426.96151.07.263305.01728
8212141681.6675.56.524534.32413
9351112291.93204.07.737155.31812
10351221223.74126.07.109674.83628
11351321949.10202.07.575125.30827
12351413184.15365.08.065945.89990
13461111044.1891.16.950994.51196
14461221023.00111.06.930494.70953
15461321178.20196.07.071745.27811
16461411155.25104.07.052074.64439

.......................................................................

........................................................................

........................................................................

14938372121061.9297.46.967834.57883
1503837221987.8694.16.895544.54436
15138372311422.71186.07.260325.22575
15238372421220.58103.07.107084.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

Reeza
Super User

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;

Rasheed
Calcite | Level 5

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

Reeza
Super User

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

PGStats
Opal | Level 21

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

PG

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

How to connect to databases in SAS Viya

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.

Discussion stats
  • 10 replies
  • 2666 views
  • 0 likes
  • 4 in conversation