嵌套在SAS中循环

时间:2014-06-05 02:31:39

标签: sas

我想使用rannor函数生成100个样本,每个样本包含两个伪正态随机变量。所以这里,100 =样本数量,25 =样本量。

%macro bootstrap(bootsample, sample, samplesize);
  data &bootsample;
  %do i=1 %to &sample;
     do j=1 to &samplesize;
     obsnumber=ceil(&samplesize*rannor(642014));
     output;
     end;
     proc univariate data=&bootsample normal;
     ods output TestsForNormality=tests;
     var obsnumber;
     histogram obsnumber;
     run;
   %end;
   run;
   %mend;

%bootstrap(bootsample,100,25);

但是我继续收到错误:声明无效或者使用的顺序不正确。 我哪里出错了?

1 个答案:

答案 0 :(得分:3)

只需移动第一个%do

%macro bootstrap(bootsample, sample, samplesize);
      %do i=1 %to &sample;
      data &bootsample;
         do j=1 to &samplesize;
         obsnumber=ceil(&samplesize*rannor(642014));
         output;
         end;
         proc univariate data=&bootsample normal;
         ods output TestsForNormality=tests;
         var obsnumber;
         histogram obsnumber;
         run;
       %end;
       run;
       %mend;

       %bootstrap(bootsample,100,25);

%MACRO BOOTSTRAP(SAMPLES=,SIZE=);
data NormalBootstrap;
    do sample=1 to &SAMPLES;
        do size=1 to &SIZE;
            value=rannor(642014);
            output;
        end;
    end;
run;
%MEND;
%BOOTSTRAP(SAMPLES=100,SIZE=25);
 proc univariate data=NormalBootstrap normal;
         ods output TestsForNormality=tests;
         var value;
         by sample;
         histogram value;
run;

(我没有sas图,所以我提交了上面没有直方图语句的代码)