Ch 8: BY-Group Processing Flashcards
Select the best answer for each question. Check your answers using the answer key in the appendix.
1.
Which of the following statements is false when you use the BY statement with the SET statement?
a.
The data sets listed in the SET statement must be indexed or sorted by the values of the BY variable or variables.
b.
The DATA step automatically creates two variables, FIRST. and LAST., for each variable in the BY statement.
c.
FIRST. and LAST. identify the first and last observation in each BY group, respectively.
d.
FIRST. and LAST. are stored in the data set.
Correct answer: d
When you use the BY statement with the SET statement, the DATA step creates the temporary variables FIRST. and LAST. They are not stored in the data set.
2.
Your data does not require any preprocessing if the observations in all of the data sets occur in which of the following patterns?
a.
Ascending or descending character order.
b.
Ascending or descending numeric order.
c.
The data must be grouped in some way.
d.
all of the above
Correct answer: d
Before you can perform BY-group processing, your data must follow a pattern. If your data is not ordered or grouped in some pattern, BY-group processing results in an error.
3.
Which temporary variables are available for DATA step programming during BY-group processing only, but are not added to the data set?
a.
FIRST.variable and LAST.variable.
b.
_N_ and _ERROR variables.
c.
Both a and b.
d.
none of the above
Correct answer: a
In the DATA step, during BY-group processing only, the temporary variables FIRST.variable and LAST.variable are available for DATA step programming, but they do not appear in the output data set.
Which program below creates the following output?
a.
proc print data=cert.credit;
by type;
run;
b.
proc sort data=cert.credit;
by type ascending;
run;
c.
proc sort data=cert.credit;
by type;
run;
d.
proc sort data=cert.credit;
by type descending;
run;
Correct answer: c
The SORT procedure sorts the data Cert.Credit by the variable Type in ascending order. You do not have to specify the order in the BY statement in PROC SORT unless you are sorting in DESCENDING order.
What statement correctly describes a BY group?
a.
It contains temporary variables that SAS creates for each BY variable.
b.
It includes all observations with the same BY value.
c.
It names a variable or variables by which the data set is sorted.
d.
It is a method of processing observations from one or more SAS data sets that are group or ordered by one or more common variables.
Correct answer: b
A BY group includes all observations with the same BY value. If you use more than one variable in a BY statement, a BY group is a group of observations with the same combination of values for these variables. Each BY group has a unique combination of values for the variables.
How does SAS determine FIRST.variable?
a.
When an observation is the first in a BY group, SAS sets the value of the FIRST.variable to 1. This happens when the value of the variable changed from the previous observation.
b.
For all other observations in the BY group, the value of FIRST.variable is 0.
c.
Both a and b.
d.
When an observation is the last in a BY group, SAS sets the value of FIRST.variable to 1.
Correct answer: c
SAS determines FIRST.variable by looking at each observation. When an observation is the first in a BY group, SAS sets the value of the FIRST.variable to 1. This happens when the value of the variable changed from the previous observation. For all other observations in the BY group, the value of FIRST.variable is 0.
Which program creates the following output?
a.
proc sort data=cert.choices out=work.choices;
by day flavor;
run;
proc print data=work.choices;
run;
b.
proc sort data=cert.choices out=work.choices;
by day;
run;
proc print data=work.choices;
run;
c.
proc print data=cert.choices out=work.choices;
by day;
run;
d.
proc sort data=cert.choices out=work.choices;
by flavor;
run;
proc print data=work.choices;
run;
Correct answer: a
The SORT procedure sorts the data Cert.Choices by the variable Day first, then Flavor in ascending order, and finally writes the sorted data set to Work.Choices.