given the SAS data set SASDATA.TWO:
X | Y |
5 | 2 |
3 | 1 |
5 | 6 |
The following SAS program is submitted:
data SASUSER.ONE SASUSER.TWO OTHER;
set SASDATA.TWO;
if X eq 5 then output SASUSER.ONE;
if Y lt 5 then output SASUSER.TWO;
output;
run;
What is the result?
A.
data set SASUSER.ONE has 5 observations
data set SASUSER.TWO has 5 observations
data set WORK.OTHER has 3 observations
B.
data set SASUSER.ONE has 2 observations
data set SASUSER.TWO has 2 observations
data set WORK.OTHER has 1 observations
C.
data set SASUSER.ONE has 2 observations
data set SASUSER.TWO has 2 observations
data set WORK.OTHER has 5 observations
D. No data sets are output. The DATA step fails execution due to syntax errors.
Check Answer注解:DATA statement可以一次建立多个data set,可以通过OUTPUT statement来指定所需写入数据的data set。如果程序中没有出现OUTPUT statement,那么SAS会自动在DATA step的最后加入OUTPUT,即一下2个程序是一样的:
data d; infile datalines; input x; output; datalines; 1 ; run; |
data d; infile datalines; input x; datalines; 1 ; run; |
本题中,出现了3个OUTPUT,第一个将SASDATA.TWO中X等于5的观测值写入SASUSER.ONE中(2个观测值),第二个将SASDATA.TWO中Y小于5的观测值写入SASUSER.TWO中(2个观测值)。第三个OUTPUT statement等价于:
OUTPUT SASUSER.ONE SASUSER.TWO OTHER;
将SASDATA.TWO中所有的数据同时写入SASUSER.ONE、SASUSER.TWO和OTHER这3个data set(3个观测值)。
SASUSER.ONE:
Obs | X | Y |
1 | 5 | 2 |
2 | 5 | 2 |
3 | 3 | 1 |
4 | 5 | 6 |
5 | 5 | 6 |
SASDATA.TWO:
Obs | X | Y |
1 | 5 | 2 |
2 | 5 | 2 |
3 | 3 | 1 |
4 | 3 | 1 |
5 | 5 | 6 |
OTHER:
Obs | X | Y |
1 | 5 | 2 |
2 | 3 | 1 |
3 | 5 | 6 |