我是SAS编程的初学者。我已经写了一段代码来理解这些东西,但我不明白为什么在获得continue语句之后,它会输出a语句。下面是代码:
data a B;
put 'entering do DATASTEP' ;
do i=1 to 4;
put 'entering do loop'" " i;
if (i=1) then do;
put 'value of i is 1'" " i;
put 'Entering the loop' ;
put j=_N_;
if _N_ = 2 then continue;
set sashelp.class(firstobs=1 obs=5);
put 'Ouside the loop';
output a;
end;
if (i=2) then do;
put 'value of i is 2'" " i;
put 'Entering the loop' ;
put j=_n_;
set sashelp.class(firstobs=6 obs=10);
put 'Ouside the loop';
output B;
end;
end;
put 'GETING OUT OF THE DATASTEP';
run;为了更清楚地了解我的疑问请求,请运行此命令,然后我们可以对输出数据集和日志进行讨论。
提前谢谢。
发布于 2016-08-04 21:00:20
在我看来,CONTINUE运行得很好。
通常,当您读取的数据超过输入数据的末尾时,SAS将停止数据步骤。如果没有CONTINUE语句,它将第6次尝试读取第一个SET语句。但是由于您跳过了一次,所以当它第六次尝试执行第二个SET语句时,它将停止。
以下是数据步骤所做工作的简化版本。注意它是如何以1,6,7,2,8,3,9,4,10,5的顺序读取记录的。
data sample;
do i=1 to 10; output; end;
run;
data _null_ ;
if _n_^=2 then do;
set sample (firstobs=1 obs=5);
put i=;
end;
set sample (firstobs=6 obs=10);
put i=;
run;
i=1
i=6
i=7
i=2
i=8
i=3
i=9
i=4
i=10
i=5https://stackoverflow.com/questions/38761471
复制相似问题