0

如果我们在下面的(错误)示例中设置(obs = 0)数据集选项,您能否解释为什么不处理数据步骤语句?

data temp;
    x=0;
run;

data wrong;
    set temp(obs=0);
    x=1;
    y=1;
    output;
    y=2;
    output;
run;

data right;
    set temp(obs=1);
    x=1;
    y=1;
    output;
    y=2;
    output;
run;

我通常希望 work.wrong 和 work.right 具有相同的输出。

4

1 回答 1

4

数据步骤停止执行的一种方式是当 SET 语句执行并读取文件结尾字符时(即没有更多记录要读取)。

因此,如果您使用 (obs=0) 设置数据集,则当执行 SET 语句时,数据步骤将停止。例如:

122  data _null_ ;
123    put _n_= "I ran" ;
124    set sashelp.class(obs=0) ;
125    put _n_= "I did not run" ;
126  run;

_N_=1 I ran
NOTE: There were 0 observations read from the data set SASHELP.CLASS.

第一个 PUT 语句执行,但第二个不执行,因为执行 SET 语句时该步骤已停止。

当您使用 (OBS=1) 设置数据集时,数据步骤将在第二次迭代时停止:

135  data _null_ ;
136    put _n_= "I ran before SET" ;
137    set sashelp.class(obs=1) ;
138    put _n_= "I ran after SET" ;
139  run;

_N_=1 I ran before SET
_N_=1 I ran after SET
_N_=2 I ran before SET
NOTE: There were 1 observations read from the data set SASHELP.CLASS.
于 2015-02-28T00:51:43.607 回答