SAS中文论坛

 找回密码
 立即注册

扫一扫,访问微社区

查看: 1556|回复: 2
打印 上一主题 下一主题

SAS官方样题(14)中的问题

[复制链接]

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
楼主
 楼主| 发表于 2005-11-27 10:48:40 | 只看该作者

SAS官方样题(14)中的问题

第4题
There are 500 observations in the data set Getobs5. What is the result of submitting the following program?
data work.getobs5(drop=obsnum);
   obsnum=5;
   set company.usa(keep=manager payroll) point=obsnum;
   stop;
run;
     a.  an error
     b.  an empty data set
     c.  a continuous loop
     d.  a data set that contains one observation
上机试验答案是B
第六题
Assuming that the data set Company.USA has five or more observations, what is the result of submitting the following program?
data work.getobs5(drop=obsnum);
   obsnum=5;
   set company.usa(keep=manager payroll) point=obsnum;
   output;
   stop;
run;
    a.  an error
    b.  an empty data set
    c.  a continuous loop
    d.  a data set that contains one observation
上机试验答案是D

那位大虾知道为什么?如果我只需要前5个记录,应该怎么做?如果我需要第5个到第100个记录,又应该怎么做
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
沙发
 楼主| 发表于 2005-11-29 15:10:04 | 只看该作者

use options obs=5

data a; set b;
options obs=5;
run;
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
板凳
 楼主| 发表于 2005-11-30 14:31:45 | 只看该作者

这段对于POINT的解释不错

[quote:cf856]POINT=variable
specifies a temporary variable whose numeric value determines which observation is read. POINT= causes the SET statement to use random (direct) access to read a SAS data set. Requirement: a STOP statement
Restriction: You cannot use POINT= with a BY statement, a WHERE statement, or a WHERE= data set option. In addition, you cannot use it with transport format data sets, data sets in sequential format on tape or disk, and SAS/ACCESS views or the SQL procedure views that read data from external files.
Restriction: You cannot use POINT= with KEY=.
Tip: You must supply the values of the POINT= variable. For example, you can use the POINT= variable as the index variable in some form of the DO statement.
Tip: The POINT= variable is available anywhere in the DATA step, but it is not added to any new SAS data set.
Featured in: Combining One Observation with Many and Reading a Subset by Using Direct Access


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.[/quote:cf856]
你的要求可以用firstobs与lastobs解决
回复 支持 反对

使用道具 举报

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

本版积分规则

QQ|小黑屋|手机版|Archiver|SAS中文论坛  

GMT+8, 2025-6-9 14:12 , Processed in 0.071367 second(s), 20 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表