jensyao

Untitled

Feb 15th, 2017
319
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. data original;
  2.     do j = 1 to 50;
  3.         rnorm = 22 + 5*rannor(345768);
  4.         output;
  5.     end;
  6. run;
  7.  
  8. data _NULL_;
  9.     if 0 then set original nobs=n;
  10.     call symputx('nrows',n);
  11.     stop;
  12. run;
  13.  
  14. %put nobs=&nrowsd;
  15. data bootsamp;
  16. do sampnum = 1 to 1000; /* Can use different number of reps */
  17.     do i = 1 to numrecs; /* Want same no. obs as in ORIGINAL */
  18.         x = round(ranuni(0)* &nrows); /*x randomly selected from values */
  19.         set original nobs = numrecs point = x; /* This selected the xth output; /* Send the selected observation to the new data set */
  20.     end;
  21. end;
  22. stop; /* Required when using point */
  23. run;
  24. /*proc print data=bootsamp; run; */
  25.  
  26. data bootorig;
  27. set original (in=a) bootsamp (drop=i);
  28. if a then sampnum = 0;
  29. run;
  30. /* proc print data=bootorig; run; */
  31.  
  32. proc means noprint data=bootorig;
  33. class sampnum;
  34. var rnorm;
  35. output out=bootout
  36.     mean=mean
  37.     var=var
  38.     n=n;
  39. run;
  40.  
  41. data calcbias;
  42.     merge bootout;
  43.     by sampnum;
  44.         sampmean = mean;
  45.         sampvar = var;
  46.     retain origmean;
  47.     if sampnum=0 then origmean=mean; /* Calculate bias and MSE */
  48. bias = sampmean-origmean;
  49. bias2 = bias*bias;
  50. mse = sampvar - bias2;
  51. run;
  52.  
  53. proc print data=calcbias;
  54. var bias mse;
  55. run;
RAW Paste Data