SAS中文论坛

标题: SAS官方样题(14)中的问题 [打印本页]

作者: shiyiming    时间: 2005-11-27 10:48
标题: 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个记录,又应该怎么做
作者: shiyiming    时间: 2005-11-29 15:10
标题: use options obs=5
data a; set b;
options obs=5;
run;
作者: shiyiming    时间: 2005-11-30 14:31
标题: 这段对于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解决




欢迎光临 SAS中文论坛 (http://mysas.net/forum/) Powered by Discuz! X3.2