data one;
input x y$;
cards;
1 Groucho
3 Harpo
3 Kart
;
data two;
input x z$;
cards;
2 Chico
4 Zeppo
;
data three;
set one;
set two;
run;
proc print data=three;
run;
连续用两个set之后结果输出十分奇怪…… Obs x y z 1 2 Groucho Chico 2 4 Harpo Zepposet的编译和执行原理是怎样的呢?是不是后一次的会覆盖上一次的结果?
davil2000 发表于 2012-11-11 21:14
In every loop, the variable's value will be replaced by the non-default new value.
Thank you~but it seems that the data loop 3 won't do because the pointer will stop after reading the obs 2 in the dataset two. The print result also presents only two obs.....
data three;
put _all_;
set one;
put _all_;
/*output;*/
set two;
put _all_;
output; /*This is always an implicit statement when there is no same statement ahead*/
run;
proc print ;
run;
the resulsts will be as follows:
Obs x y z
1 2 Groucho Chico
2 4 Harpo Zeppo
For data set two, there exist no obs corresponding to _N_=3. the data loop will leave out here. so the results will be only 2 obs.
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.
davil2000 发表于 2012-11-11 21:11
In data loop 1(_N_=1):
x=1 y=Groucho z= _ERROR_=0 _N_=1
x=2 y=Groucho z=Chico _ERROR_=0 _N_=1
根据sas certificate prep guide 第十三章 combining sas data set one-to-onereading 里面有这样一句话 the data step stops after it has read the last observation from the smallest data set.但是通过log的确从数据集 WORK.ONE. 读取了 3 个观测。难道书不正确?怎么理解?