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