楼主: 若水烟寒
3898 17

连续使用两个set之后的结果 [推广有奖]

11
moyunzheng 发表于 2012-11-12 09:09:03
若水烟寒 发表于 2012-11-11 21:40
Thank you~but it seems that the data loop 3 won't do because the pointer will stop after reading t ...
sas给每个set分配一个指针,指针读到文件的结尾(EOF)时,退出Data步.同理,以下的结果Result中,其观测数为a,b,c,d中最小的那个观测数.
  1. data result;
  2. set a;
  3. set b;
  4. set c;
  5. set d;
  6. run;
复制代码

12
pobel 在职认证  发表于 2012-11-12 09:51:42
若水烟寒 发表于 2012-11-11 21:40
Thank you~but it seems that the data loop 3 won't do because the pointer will stop after reading t ...
Something about where a DATA Step starts and ends:

1. A DATA Step always starts from the "Data" statement

2. A DATA Step stops at:
  1. /*
  2.   a. whenever a "STOP" statement is executed;
  3.    in the following example,the first two "PUT" statement will be executed once and the last "PUT" statement will not be executed. Dataset test_a will contain 0 observations because the implicit OUTPUT was not done.
  4. */
  5.    data test_a;
  6.        put _all_;
  7.        set sashelp.class;
  8.            put _all_;
  9.            stop;
  10.            put _all_;
  11.         run;

  12. /*
  13.         b. if this DATA Step didn't read data from the datalines or any other datasets, the DATA Step stops at "RUN" statement;
  14.     For example, the following data step only has one iteration.
  15. */

  16. data test_b;
  17.     put _all_;
  18.     x=1;
  19.         y=2;
  20.    put _all_;
  21. run;

  22. /* c. If a DATA Step reads data from the datalines or other datasets, then this DATA Step stops when there's no more data available to read;
  23.    In other words, it stops at the "SET" or "INPUT" statement when SAS is trying to read more data but nothing can be read.
  24. */
  25. data test_c1;
  26.     put "Before input:" _n_;
  27.         input x;
  28.         put "After input: " _n_;
  29.         cards;
  30. 1
  31. 2
  32. 3
  33. ;

  34. data test_c2;
  35.    put "Before set: " _n_;
  36.    set test_c1;
  37.    put "After set: " _n_;
  38. run;

  39. *** A special occasion: If the "SET" statement is not executed at a certain LOOP of the DATA step, then the DATA step stops at the "RUN" statement of that iteration and put the note "DATA STEP stopped due to looping." to the log window;
  40. data test_c3;
  41.    put "====================";
  42.    put "Before set: " _n_;
  43.    if _n_ ne 2 then set sashelp.class;
  44.    put "After set: " _n_;
  45. run;
复制代码
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
若水烟寒 + 1 + 1 + 1 热心帮助其他会员

总评分: 学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

和谐拯救危机

13
zkymath 在职认证  发表于 2012-11-12 13:16:18
推荐你看一看姚志勇《SAS编程与数据挖掘商业案例》,写得很明白

14
若水烟寒 发表于 2012-11-12 13:35:03
davil2000 发表于 2012-11-12 08:30
By default, every DATA step contains an implicit OUTPUT statement at the end of each iteration that  ...
I have a better understanding about the output statement now. Thank you!

15
若水烟寒 发表于 2012-11-12 13:40:49
pobel 发表于 2012-11-12 09:51
Something about where a DATA Step starts and ends:

1. A DATA Step always starts from the "Data" ...
Thank you very much~~~The data step is very interesting~

16
若水烟寒 发表于 2012-11-12 13:41:54
zkymath 发表于 2012-11-12 13:16
推荐你看一看姚志勇《SAS编程与数据挖掘商业案例》,写得很明白
好~最近看的是朱世武那本……

17
龙潭丰乐 学生认证  发表于 2012-11-12 23:16:37
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 个观测。难道书不正确?怎么理解?

18
Alanglj 在职认证  发表于 2012-12-2 23:31:05
真心看不懂。。。

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-9 02:18