Chapter 22: Conditioning Raw Data Files

  1. Correct answer: d
    In order to create one observation per detail record, it is necessary to distinguish between header and detail records. Use a RETAIN statement to keep header data as part of each observation until the next header record is encountered. You also need to use the @ line-hold specifier to hold the current record so that other values in the record can be read.
  2. Correct answer: a
    An INPUT statement is used to read the value for code. The single @ sign at the end of the INPUT statement holds the current record for a later INPUT statement in the same iteration of the DATA step.
  3. Correct answer: b
    The IF-THEN statement defines the condition that Record equals C and executes an INPUT statement to read the value for Amount when the condition is true. C must be enclosed in quotation marks and must be specified exactly as shown because it is a character value.
  4. Correct answer: b
    The value of Vegetable is retained across iterations of the DATA step. As the sixth iteration begins, the INPUT statement reads the value for code and holds the record, so that the values for Variety and Supplier can be read with an additional INPUT statement.
  5. Correct answer: c
    This program creates one observation for each detail record. The RETAIN statement retains the value for Fruit as part of each observation until the values for Variety and Price can be read. The DROP= option in the DATA statement prevents the variable for type from being written to the data set.
  6. Correct answer: a
    The IF-THEN statement defines the condition that Record equals A and specifies a simple DO group. The keyword DO indicates that several executable statements follow until the DO group is closed by an END statement. The value A must be enclosed in quotation marks and specified exactly as shown because it is a character value.
  7. Correct answer: d
    _N_ is an automatic variable whose value is the number of times the DATA step has begun to execute. The expression _n_ > 1 defines a condition where the DATA step has executed more than once. When the conditions code='X' and _n_ > 1 are true, an OUTPUT statement is executed, and Total is initialized to zero. Thus, each header record except the first one causes an observation to be written to the data set.
  8. Correct answer: d
    The condition is false, so the values for ID and Address are not read. Instead, the ELSE statement is executed and defines another condition that might or might not be true.
  9. Correct answer: d
    You can determine when the current record is the last record in an external file by specifying the END= option in the INFILE statement. last is a temporary numeric variable whose value is zero until the last line is read. Last has a value of 1 after the last line is read. Like automatic variables, the END= variable is not written to the data set.
  10. Correct answer: b
    This program creates one observation for each header record and combines information from each detail record into the summary variable, Total. When the value of Type is D and the value of _N_ is greater than 1, the OUTPUT statement executes, and the values for Department, Total and Extension are written to the data set as the first observation. The variables _N_ , Last, Type, and Amount are not written to the data set.
Last updated: January 10, 2018
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.151.220