楼主: shenliang_111
5075 9

[原创博文] point i 和 do until last 的区别 [推广有奖]

  • 3关注
  • 12粉丝

教授

15%

还不是VIP/贵宾

-

威望
0
论坛币
14 个
通用积分
0.4174
学术水平
20 点
热心指数
26 点
信用等级
12 点
经验
17989 点
帖子
478
精华
0
在线时间
1627 小时
注册时间
2011-2-24
最后登录
2025-8-3

楼主
shenliang_111 发表于 2011-6-27 10:32:24 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
看两段程序:
data comb;
set a;
do until  (last);
set b end=last;
end;
run;

data comb;
set a;
do i=1 to nobs;
set b  point=i nobs=nobs;
run;
我发现,第一段程序最后形成的comb只包括数据集a的第一条观测,可以解释为until last 的使用使得data 步循环提前终止
第二段程序形成的comb包括数据集a的所有观测,解释为是读完数据集a才使data步终止循环,事实上,我们使用point选项时,经常要用到stop,我想问各个好朋友们,
point i为什么有无限循环功能,until last为什么只循环一次,两者的机制区别在哪里呢?谢谢了
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Point until Last int data步 朋友 程序

已有 1 人评分热心指数 收起 理由
crackman + 1 鼓励积极发帖讨论

总评分: 热心指数 + 1   查看全部评分

本帖被以下文库推荐

沙发
shenliang_111 发表于 2011-6-27 21:52:46
自己顶上去.....

藤椅
soporaeternus 发表于 2011-6-28 09:12:16
第一点,偷个懒抄了点SAS Help的原话
CAUTION:
Continuous loops can occur when you use the POINT= option.
When you use the POINT= option, you must include a STOP statement to stop DATA step processing, programming logic that checks for an invalid value of the POINT= variable, or both. Because POINT= reads only those observations that are specified in the DO statement, SAS cannot read an end-of-file indicator as it would if the file were being read sequentially. Because reading an end-of-file indicator ends a DATA step automatically, failure to substitute another means of ending the DATA step when you use POINT= can cause the DATA step to go into a continuous loop. If SAS reads an invalid value of the POINT= variable, it sets the automatic variable _ERROR_ to 1. Use this information to check for conditions that cause continuous DO-loop processing, or include a STOP statement at the end of the DATA step, or both.  
Data步中止的一个方法是读到eof标识,point读法读不到,只有读到a的eof才终止。do until在_n_=1的时候读到了b的eof,故中止。都加上output的话,point读法类似于做了一个笛卡尔积,就比较明显了。

第二点,我也很崇拜hopewell大大,大家共勉。

第三点,原地召唤hopewell大大.......
已有 2 人评分经验 学术水平 热心指数 信用等级 收起 理由
crackman + 100 + 2 鼓励积极发帖讨论
pobel + 1 + 1 + 1 我很赞同

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

Let them be hard, but never unjust

板凳
yugao1986 发表于 2011-6-28 11:33:24
同样膜拜BASE用神的牛
三人行必有我师

报纸
pobel 在职认证  发表于 2011-6-28 11:41:52
第一段程序:
1. _N_=1:
      1). 读取数据集a 的第一条记录;
   2). do... until... 顺序读取数据集b的所有记录;
   3). run;输出记录(a第一条记录中的变量值和b 最后一条记录中的变量值);

2. _N_=2:
      1). 读取数据集a的第二条记录;
   2). do... until... 试图继续读取数据集b的记录未果 (b在_n_=1时已读到最后一条);
   3). 中止(没有输出).
已有 1 人评分经验 热心指数 收起 理由
crackman + 100 + 2 鼓励积极发帖讨论

总评分: 经验 + 100  热心指数 + 2   查看全部评分

和谐拯救危机

地板
shenliang_111 发表于 2011-6-28 22:20:42
3# soporaeternus
看完hopewell的程序了,还有几个关于hash object的程序不能理解,现在正在看您的程序...嘻嘻....是您告诉我们这些新人要多看程序才能学好sas的...哈哈..
事实也的确如此...

7
shenliang_111 发表于 2011-6-28 22:23:37
5# pobel
但是point i即便已经停留在最后一条记录了,当_n_变为2时,它还会再次重新回到b的第一条记录的..无限循环哦..

8
shenliang_111 发表于 2011-6-28 22:29:53
3# soporaeternus
为什么叫大大....他真的好厉害...佩服....程序写的很漂亮...貌似什么模块都懂的...

9
kuhasu 发表于 2011-6-28 23:09:13
召唤hopewell大大~

你们给他发个短信不就行了?

10
bobguy 发表于 2011-6-29 08:20:17
shenliang_111 发表于 2011-6-27 10:32
看两段程序:
data comb;
set a;
do until  (last);
set b end=last;
end;
run;

data comb;
set a;
do i=1 to nobs;
set b  point=i nobs=nobs;
run;
我发现,第一段程序最后形成的comb只包括数据集a的第一条观测,可以解释为until last 的使用使得data 步循环提前终止
第二段程序形成的comb包括数据集a的所有观测,解释为是读完数据集a才使data步终止循环,事实上,我们使用point选项时,经常要用到stop,我想问各个好朋友们,
point i为什么有无限循环功能,until last为什么只循环一次,两者的机制区别在哪里呢?谢谢了
1) A usual SAS data step does more than it looks. For example, it implements a internal loop of observations so that one only needs define an operation for an observation. It has an output statement 'slightly' above a run statement. If one uses put _n_ one will see the internal loop counts.
But if one put a set statement explicitly into a do loop, then the internal loop will be overwritten. This sort style has some advantages if one fully understans the guts of SAS data step.

*****explicit loop****;
data repeat;
do until  (last);
set b end=last;
output;
put _n_=;
end;
run;

****a usual way in SAS books;

data repeat;
set b;
put _n_=;
run;

2) The point option on a set statement instructs a direct access to a data set. It provides some advantages. For example, one can create a reverse order data set by reversing points (do i=nobs to 1 by -1).  Or one may want to read obs in { 1, 101, 201, ...}. A direct access is usually slower than a sequential access.  Under a direct access one needs to tell SAS/data step when to stop.

data repeat;
do i=1 to nobs;
set b  point=i nobs=nobs;
output;
end;
stop;
run;

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-9 12:38