| Quiz:
Merging
SAS Data Sets
Select the best answer for each question and click Score My Quiz.
-
Assuming that you want the variables
Months, ID, and Lab in the
data set Research.Results, which of the following
programs should you submit?
-
What happens if you merge the
following data sets by the variable
SSN?
| SSN |
Age |
| |
32 |
| 029-46-9261 |
39 |
| 074-53-9892 |
34 |
| 228-88-9649 |
32 |
| 442-21-8075 |
12 |
| 446-93-2122 |
36 |
| 776-84-5391 |
28 |
| 929-75-0218 |
27 |
|
| SSN |
Age |
Date |
| 029-46-9261 |
37 |
02/15/95 |
| 074-53-9892 |
32 |
05/22/97 |
| 228-88-9649 |
30 |
03/04/96 |
| 442-21-8075 |
10 |
11/22/95 |
| 446-93-2122 |
34 |
07/08/96 |
| 776-84-5391 |
26 |
12/15/96 |
| 929-75-0218 |
25 |
04/30/97 |
|
-
Suppose you merge data sets Data1
and Data2 below.
Data1
| ID |
Sex |
Age |
| 1129 |
F |
48 |
| 1274 |
F |
50 |
| 1387 |
F |
57 |
| 2304 |
F |
16 |
| 2486 |
F |
63 |
| 4425 |
F |
48 |
| 4759 |
F |
60 |
| 5438 |
F |
42 |
| 6488 |
F |
59 |
| 9012 |
F |
39 |
| 9125 |
F |
56 |
|
Data2
| ID |
Height |
Weight |
| 1129 |
61 |
137 |
| 1387 |
64 |
142 |
| 2304 |
61 |
102 |
| 5438 |
62 |
168 |
| 6488 |
64 |
154 |
| 9012 |
63 |
157 |
| 9125 |
64 |
159 |
|
Which output does the following program create?
data merged;
merge data1(in=in1) data2(in=in2); by id; if in1 and in2;
run; proc print data=merged; run;
-
What happens when you submit the
following program?
proc sort data=data1;
by id; run; proc sort data=data2; by id;
run; data merged; merge data1 data2; by id; run;
-
If you merge data sets DataA
and DataB below by
ID, what is the value
of Units in the fourth observation in the new data set?
DataA
| ID |
Type |
Units |
| 1129 |
A |
48 |
| 1129 |
A |
50 |
| 1129 |
A |
57 |
| 2304 |
O |
16 |
| 2486 |
B |
63 |
|
DataB
| ID |
Code
|
Units |
| 1129 |
63
|
32 |
| 1387 |
64
|
67 |
| 2304 |
61
|
45 |
| 5438 |
62
|
39 |
| 6488 |
65
|
27 |
|
-
If you merge data sets DataA
and DataB below by
ID, what values does
the PDV contain when the pointer first moves to 2486 in DataA?
DataA
| ID |
Type |
Units |
| 1129 |
A |
48 |
| 1129 |
A |
50 |
| 1129 |
A |
57 |
| 2304 |
O |
16 |
| 2486 |
B |
63 |
|
DataB
| ID |
Code
|
Units |
| 1129 |
63
|
32 |
| 1387 |
64
|
67 |
| 2304 |
61
|
45 |
| 5438 |
62
|
39 |
| 6488 |
65
|
27 |
|
-
In the data sets DataC
and DataD below, assume that character variables
are left-justified and numeric variables are right-justified. Which
program below may produce undesirable results?
DataC
|
Item
|
Region |
Date
|
Cost |
|
1040-A
|
W |
01/12/1999
|
62.50 |
|
1129
|
S |
03/19/2000
|
119.00 |
|
1129
|
E |
05/22/2000
|
75.25 |
|
2304-IR
|
W |
12/12/2001
|
108.10 |
|
2486
|
N |
05/06/1999
|
23.45 |
|
DataD
|
ItemNumber
|
Region
|
Date
|
|
1129
|
1006
|
May
12
|
|
1387
|
1008
|
May
7
|
|
2304
|
1110
|
June
11
|
|
5438090
|
1006
|
July
4
|
|
6488093
|
1007
|
May
9
|
|
-
What happens if you submit the
following program to merge DataE and DataF
below?
data merged;
merge datae dataf;
by id;
run;
DataE
| ID |
Type |
Units |
| 2304 |
O |
16 |
| 1129 |
A |
48 |
| 1129 |
A |
50 |
| 1129 |
A |
57 |
| 2486 |
B |
63 |
|
DataF
| ID |
Code |
Units |
| 6488 |
65 |
27 |
| 1129 |
63 |
32 |
| 5438 |
62 |
39 |
| 2304 |
61 |
45 |
| 1387 |
64 |
67 |
|
-
If you merge DataG
and DataH below by
ID, how many observations
does the new data set contain?
DataG
| ID |
Name |
Dept |
Project |
| 000 |
Miguel |
A12 |
Document |
| 111 |
Fred |
B45 |
Survey |
| 222 |
Diana |
B45 |
Document |
| 888 |
Monique |
A12 |
Document |
| 999 |
Vien |
D03 |
Survey |
|
DataH
| ID |
Name |
Hours |
| 111 |
Fred |
35 |
| 222 |
Diana |
40 |
| 777 |
Steve |
0 |
| 888 |
Monique |
37 |
|
-
If you merge data sets DataI,
DataJ, and DataK by
ID,
what is the value of Bonus in the third observation in
the new data set?
DataI
| ID |
Name |
| 1 |
Nay
Rong |
| 2 |
Kelly
Windsor |
| 3 |
Julio
Meraz |
| 4 |
Richard
Krabill |
|
DataJ
| ID |
Sale |
| 1 |
$28,000 |
| 2 |
$30,000 |
| 2 |
$40,000 |
| 3 |
$15,000 |
| 3 |
$20,000 |
| 3 |
$25,000 |
| 4 |
$35,000 |
|
DataK
| ID |
Bonus |
| 1 |
$2,000 |
| 2 |
$4,000 |
| 3 |
$3,000 |
| 4 |
$2,500 |
|
|