首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SET语句的后端处理和SAS中Continue和Leave语句的使用

SET语句的后端处理和SAS中Continue和Leave语句的使用
EN

Stack Overflow用户
提问于 2016-08-04 15:50:41
回答 1查看 35关注 0票数 1

我是SAS编程的初学者。我已经写了一段代码来理解这些东西,但我不明白为什么在获得continue语句之后,它会输出a语句。下面是代码:

代码语言:javascript
复制
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;

为了更清楚地了解我的疑问请求,请运行此命令,然后我们可以对输出数据集和日志进行讨论。

提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2016-08-04 21:00:20

在我看来,CONTINUE运行得很好。

通常,当您读取的数据超过输入数据的末尾时,SAS将停止数据步骤。如果没有CONTINUE语句,它将第6次尝试读取第一个SET语句。但是由于您跳过了一次,所以当它第六次尝试执行第二个SET语句时,它将停止。

以下是数据步骤所做工作的简化版本。注意它是如何以1,6,7,2,8,3,9,4,10,5的顺序读取记录的。

代码语言:javascript
复制
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=5
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38761471

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档