Select the best answer
for each question. Check your answers using the answer key in the
appendix.
-
When you write a DATA
step to create one observation per detail record, what do you need
to do?
-
Distinguish between
header and detail records.
-
Keep the header record
as a part of each observation until the next header record is encountered.
-
Hold the current value
of each record type so that the other values in the record can be
read.
-
-
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?
-
Which SAS statement
checks for the condition that Record equals C and executes a single
statement to read the values for Amount?
-
if record=c then input @3 Amount comma7.;
-
if record='C' then input @3 Amount comma7.;
-
if record='C' then do input @3 Amount comma7.;
-
if record=C then do input @3 Amount comma7.;
-
After the value for
code is read in the sixth iteration, which illustration of the program
data vector is correct?
data perm.produce (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.produce;
run;
-
What happens when the
fourth iteration of the DATA step is complete?
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;
-
All of the values in
the program data vector are written to the data set as the third observation.
-
All of the values in
the program data vector are written to the data set as the fourth
observation.
-
The values for Fruit,
Variety, and Price are written to the data set as the third observation.
-
The values for Fruit,
Variety, and Price are written to the data set as the fourth observation.
-
Which SAS statement
indicates that several other statements should be executed when Record
has a value of A
?
-
Which is 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;
-
_N_ equals the number
of times the DATA step has begun to execute.
-
When code='X' and _n_
> 1 are true, an OUTPUT statement is executed.
-
Each header record causes
an observation to be written to the data set.
-
-
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.;
-
The values for ID and
Address are read.
-
The values for Charge
are read.
-
Type is assigned the
value of V
.
-
The ELSE statement is
executed.
-
What happens when Last
has a value other than zero?
data perm.househld (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;
-
-
The OUTPUT statement
writes the last observation to the data set.
-
The current value of
last is written to the DATA set.
-
-
Based on the values
in the program data vector, what happens next?
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;
-
All the values in the
program data vector are written to the data set as the first observation.
-
The values for Department,
Total, and Extension are written to the data set as the first observation.
-
The values for Department,
Total, and Extension are written to the data set as the fourth observation.
-
The value of Last changes
to 1
.