|
|
板凳

楼主 |
发表于 2009-11-24 14:26:42
|
只看该作者
Re: 请教高手:关于OUTPUT语句的运行机制
Implicit versus Explicit Output
By default, every DATA step contains an implicit OUTPUT statement at the end of each iteration that tells SAS to write observations to the data set or data sets that are being created. Placing an explicit OUTPUT statement in a DATA step overrides the automatic output, and SAS adds an observation to a data set only when an explicit OUTPUT statement is executed. Once you use an OUTPUT statement to write an observation to any one data set, however, there is no implicit OUTPUT statement at the end of the DATA step. In this situation, a DATA step writes an observation to a data set only when an explicit OUTPUT executes. You can use the OUTPUT statement alone or as part of an IF-THEN or SELECT statement or in DO-loop processing.
清晰 和 隐含的 Output 命令
默认情况下,在每次循环的最后,每个数据步包含一个隐含的Output命令,用于告诉SAS把 观测值写进正在创建的数据集里。如果在数据步里写一个清晰的 Output,那这个命令就覆盖了自动的Output,因此,只有当执行这个清晰的Output时,SAS才把这个观测加入到数据集里。一旦你用Output来把一个观测写进数据集,在数据步的末尾,就没有了隐含的Output命令。
data b;
set a;
if x=2 then output;
y=2;
run;
在你这个程序里,if-then语句里有了一个清晰的Output,意味着这个数据步没有了隐含的Output,也就是 y=2 后面是没有output的。所以b里面也就是空的了。
如果我们做如下修改,在y=2后面加上 output,如下:
data b;
set a;
if x=2 then output;
y=2;
output;
run;
b 里面就会有 一个obs了 |
|