SAS Base (50)

Given the SAS data set WORK.ONE:

Id Char1
111 A
158 B
329 C
644 D

and the SAS data set WORK.TWO:

Id Char2
111 E
538 F
644 G

The following program is submitted:

data WORK.BOTH;
set WORK.ONE WORK.TWO;
by Id;
run;

What is the first observation in SAS data set WORK.BOTH?

A.

Id Char1 Char2
111 A

B.

Id Char1 Char2
111 E

C.

Id Char1 Char2
111 A  E

D.

Id Char1 Char2
644 D G
Check Answer
Answer: A

注解:SET statement的作用是将多个data set合并,但不会对观测值进行合并。题目中,新data set BOTH中将包含ONE和TWO中所有的变量,BY statement作用是使新data set根据ID升序排列,所以ONE中的第一条数据将成为BOTH中的第一条数据,由于该观测值中没有Char2变量,所以输出结果中显示为missing。完整的BOTH为:

Obs Id Char1 Char2
1 111 A
2 111 E
3 158 B
4 329 C
5 538 F
6 644 D
7 644 G

如需对观测值合并,应当使用MERGE,具体请参考SAS Base (28)

Leave a Reply

Your email address will not be published. Required fields are marked *