2016-08-04 243 views
1

我是初学SAS编程人员。 我已经写了一段代码来理解这些东西,但是我没有得到为什么在得到continue语句之后它将输出一个语句。 下面给出的是代码:后端处理SET语句以及在SAS中使用Continue和Leave语句

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; 

有关我的疑问请求。请运行这更清晰,那么我们就可以有一个关于输出数据集和日志的讨论。

在此先感谢。

+0

你是怎么编写你不明白的代码的?你到底想要做什么? – Cristina

+0

感谢克里斯蒂娜的回应。我不想从这些代码中获得任何要求。我只是想了解输出是如何生成到两个数据集中的,以及为什么Continue Statement没有按照其规范工作。据我说,在数据集A中应该只有4条记录,因为我已经使用了_N_ = 2的继续声明,但是我得到了5条记录。第二条记录不应进入数据集A,因为continue语句在输出A之前。请让我知道,如果您遇到我的问题。 –

+0

啊哈,好的!感谢您的澄清 - 您可以将这些信息添加到您的帖子中,以使其更易于理解。 – Cristina

回答

2

它在我看来像CONTINUE工作正常。

正常情况下,当您读取输入数据的末尾时,SAS会停止数据步骤。没有CONTINUE语句,当它试图从第一次SET语句读取第6次。但是,既然你跳过它,它会在第6次尝试执行第二条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=5