SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Searchback||next

Quiz: Reading Hierarchical Files

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

  1. Which of the following is true for the RETAIN statement?

     a.   The RETAIN statement names a variable whose value is retained across iterations of the DATA step.
     b.   You can specify more than one variable in the RETAIN statement.
     c.   If you do not specify a variable in the RETAIN statement, then the values of all the variables in the data set are retained.
     d.   all of the above

  2. Which SAS statement reads the value for code (in the first field), and then holds the value until an INPUT statement reads the remaining value in each observation in the same iteration of the DATA step?

    1---+----10---+----20---+----30
    01 Office Supplies
    02 Paper Clips
    02 Tape
    01 Art Supplies
    02 Crayons
    02 Finger Paint
    02 Construction Paper

     a.  
    input code $2. @; 
     b.  
    input code $2. @@;
     c.  
    retain code;
     d.   none of the above

  3. Which SAS statement checks for the condition that Record equals C and executes a single statement to read the values for Amount?

     a.  
    if record=c then input @3 Amount comma7. 
     b.  
    If record='C' then input @3 Amount comma7. 
     c.  
    If record='C' then do input @3 Amount comma7. 
     d.  
    If record=C then do input @3 Amount comma7. 

  4. As the DATA step begins the sixth iteration, which illustration of the program data vector is correct?

    1---+----10---+----20---+----30
    H Lettuce
    P Green Leaf  Quality Growers
    P Iceberg     Pleasant Farm
    P Romaine     Quality Growers
    H Squash
    P Yellow      Tasty Acres
    P Zucchini    Pleasant Farm

    data perm.suppliers (drop=code);
       infile orders;
       retain Vegetable;
       input code $1. @;
       if code='H' then input @3 Vegetable $6.;
       if code='P';
       input @3 Variety : $10. @15 Supplier : $15.;
    run;
    proc print data=perm.suppliers;
    run;
    

     a.   Program Data Vector
     b.  
    Program Data Vector 
     c.  
    Program Data Vector
     d.   Program Data Vector

  5. What happens when the fourth iteration of the DATA step is complete?

    1---+----10---+----20---+----30
    F Apples
    V Gala             $2.50
    V Golden Delicious $1.99
    V Rome             $2.35
    F Oranges
    V Navel            $2.79
    V Temple           $2.99
    data perm.orders (drop=type);
       infile Produce;
       retain Fruit;
       input type $1. @;
       if type='F' then input @3 Fruit $7.;
       if type='V';
       input @3 Variety : $16. @20 Price comma5.;
    run; 

     a.   All of the values in the program data vector are written to the data set as the third observation.
     b.   All of the values in the program data vector are written to the data set as the fourth observation.
     c.   The values for Fruit, Variety, and Price are written to the data set as the third observation.
     d.   The values for Fruit, Variety, and Price are written to the data set as the fourth observation.

  6. Which SAS statement indicates that several other statements should be executed when Record has a value of A?

    1---+----10---+----20---+----30
    A 124153-01 
    C $153.02 
    D $20.00 
    D $20.00

     a.  
    if record='A' then do;
     b.  
    if record=A then do; 
     c.  
    if record='A' then;
     d.  
    if record=A then;  

  7. Which is not true for the following statements (X indicates a header record)?
    if code='X' then do;
       if _n_ > 1 then output;
       Total=0;
       input Name $ 3-20;
    end;

     a.   _N_ equals the number of times the data step has begun to execute.
     b.   When code='X' and _n_ > 1 are true, an OUTPUT statement is executed.
     c.   Each header record causes an observation to be written to the data set.
     d.   When code='X' is true, Total is initialized to zero.

  8. What happens when the condition Type='P' is false?
    if type='P' then input @3 ID $5. @9 Address $20.;
    else if type='V' then input @3 charge 6.; 

     a.   The values for ID and Address are read.
     b.   The values for Charge are read.
     c.   Type is assigned the value of V.
     d.   The ELSE statement is executed.

  9. What happens when Last has a value other than zero?
    data perm.household (drop=code);
       infile citydata end=last;
       retain Address;
       input type $1. @;
       if code='A' then do;
          if _n_ > 1 then output;
          Total=0;
          input Address $ 3-17;
       end;
       else if code='N' then total+1;
       if last then output;
    run;

     a.   Last has a value of 1.
     b.   The OUTPUT statement writes the last observation to the data set.
     c.   The current value of Last is written to the DATA set.
     d.   a and b

  10. Based on the values in the program data vector, what happens next?

    Program Data Vector

    1---+----10---+----20---+----30
    D Accounting   x3808
    S Paper Clips  $2.50
    S Paper        $4.95
    S Binders      $9.05
    D Personnel    x3810
    S Markers      $8.98
    S Pencils      $3.35

    
    data work.supplies (drop=type amount);
       infile orders end=last;
       retain Department Extension;
       input type $1. @;
       if type='D' then do;
          if _n_ > 1 then output;
          Total=0;
          input @3 Department $10. @16 Extension $5.;
       end;
       else if type='S' then do;
          input @16 amount comma5.;
          total+amount;
          if last then output;
      end;
    run;
    

     a.   All the values in the program data vector are written to the data set as the first observation.
     b.   The values for Department, Total, and Extension are written to the data set as the first observation.
     c.   The values for Department, Total, and Extension are written to the data set as the fourth observation.
     d.   The value of Last changes to 1.



back||next

Terms of Use & Legal Information | Privacy Statement