SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Searchback||next

Quiz: Merging SAS Data Sets

Select the best answer for each question and click Score My Quiz.

  1. Assuming that you want the variables Months, ID, and Lab in the data set Research.Results, which of the following programs should you submit?

     a.  
    data research.results;
       merge lab1(drop=protocol) lab2;
    by testnumber;
    if months>12; ID=lab||protocol; run;
     
     b.  
    data research.results(drop=protocol);
       merge lab1 lab2;
    by testnumber;
    if months>12; ID=lab||protocol; run;
     
     c.  
    data research.results;
       merge lab1(keep=months) lab2(keep=lab);
    by testnumber;
    if months>12; ID=lab||protocol; run;
     
     d.   any of the above

  2. 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

     a.   The values of Age in the first data set overwrite values of Age in the second data set.
     b.   The values of Age in the second data set overwrite values of Age in the first data set.
     c.   The DATA step fails because the two data sets contain like-named variables with different values.
     d.   The values of Age in the second data set are set to missing.

  3. 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;

     a.  
    Obs ID Sex Age Height Weight
    1 1129 F 48 61 137
    2 1274 F 50 . .
    3 1387 F 57 64 142
    4 2304 F 16 61 102
    5 2486 F 63 . .
    6 4425 F 48 . .
    7 4759 F 60 . .
    8 5438 F 42 62 168
    9 6488 F 59 64 154
    10 9012 F 39 63 157
    11 9125 F 56 64 159

     b.  
    Obs ID Sex Age Height Weight
    1 1129 F 48 61 137
    2 1387 F 50 64 142
    3 2304 F 57 61 102
    4 5438 F 16 62 168
    5 6488 F 63 64 154
    6 9012 F 48 63 157
    7 9125 F 60 64 159
    8 5438 F 42 . .
    9 6488 F 59 . .
    10 9012 F 39 . .
    11 9125 F 56 . .

     c.  
    Obs ID Sex Age Height Weight
    1 1129 F 48 61 137
    2 1387 F 57 64 142
    3 2304 F 16 61 102
    4 5438 F 42 62 168
    5 6488 F 59 64 154
    6 9012 F 39 63 157
    7 9125 F 56 64 159

     d.   none of the above

  4. 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;

     a.   The contents of Data1 and Data2 are permanently sorted, and the DATA step runs successfully.
     b.   The contents of Data1 and Data2 are temporarily sorted, and the contents of Merged are permanently sorted. The DATA step runs successfully.
     c.   The contents of Data1 and Data2 are temporarily sorted and written to output data sets. The DATA step fails because it reads the original, unsorted data.
     d.   The DATA step may fail because not all values of the BY variable necessarily exist in both data sets.

  5. 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

     a.   missing
     b.   16
     c.   39
     d.   67

  6. 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

     a.   The value of ID changes to 2486 and the remaining values are retained from the previous observation.
     b.   The program data vector is initialized to missing.
     c.   The value of ID changes to 2486 and the remaining values are initialized to missing.
     d.   none of the above

  7. 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

     a.  
    data merged2;
       merge datac datad(rename=(itemnumber=Item));
    by item;
    run;
     
     b.  
    data merged2;
       merge datac datad(rename=(region=RegionCode));
    by item;
    run;
     
     c.  
    data merged2;
       merge datac(rename=(date=ExpirationDate)) datad;
    by item;
    run;
     
     d.   all of the above

  8. 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

     a.   The Merged data set contains some missing values because not all observations have matching observations in the other data set.
     b.   The Merged data set contains 8 observations.
     c.   The DATA step produces errors.
     d.   Values for Units in DataF overwrite values of Units in DataE.

  9. 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

     a.   4
     b.   5
     c.   6
     d.   9

  10. 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

     a.   $4,000
     b.   $3,000
     c.   missing
     d.   can't tell from the information given



back||next

Terms of Use & Legal Information | Privacy Statement