SAS Base (35)

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
Answer: A

注解: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

SAS Base (21)

Given the SAS data set WORK.PRODUCTS:

ProdId Price ProductType Sales Returns
K12S 95.50 OUTDOOR 15 2
B132S 2.99 CLOTHING 300 10
R18KY2 51.99 EQUIPMENT 25 5
3KL8BY 6.39 OUTDOOR 125 15
DY65DW 5.60 OUTDOOR 45 5
DGTY23 34.55 EQUIPMENT 67 2

The following SAS program is submitted:

data WORK.OUTDOOR WORK.CLOTH WORK.EQUIP;
set WORK.PRODUCTS;
if Sales GT 30;
if ProductType EQ ‘OUTDOOR’ then output WORK.OUTDOOR;
else if ProductType EQ ‘CLOTHING’ then output WORK.CLOTH;
else if ProductType EQ ‘EQUIPMENT’ then output WORK.EQUIP;
run;

How many observations does the WORK.OUTDOOR data set contain?
A. 1
B. 2
C. 3
D. 6

Check Answer
Answer: B

注解:Outdoor data set中的数据需要满足2个条件,Sales大于30以及ProductType为OUTDOOR,只有第四和第五个observation满足条件。