Midterm 2 (Ch 4-7) Flashcards
In which phase does the DATA step check for syntax errors?
Compilation
Checking for syntax errors is the first step in the compilation phase.
Which statement is used to read a SAS data set in a DATA step?
SET statement
The SET statement indicates the table that will be read. The DATA statement indicates the table that will be created or updated.
To process an Excel file with the DATA step, you must first create a copy of the data as a SAS table.
False
You can use the XLSX LIBNAME engine to read an Excel worksheet directly and process the data with the DATA step.
What is the name of the ouput data set in the program below?
data work.us;
set orion.sales;
where Country=’US’;
run;
work.us
The output table is listed in the DATA statement.
The data set orion.sales contains nine columns. Given this DATA step, how many columns does work.comp have?
data work.comp;
set orion.sales;
keep employee_id status job_title salary;
run;
Four
Only the four columns listed in the KEEP statement are written to the work.comp table.
Given the assignment statement below, what is the value of AvgExp for the observation that is shown?
AvgExp=mean(Exp1, Exp2, Exp3, Exp4);
Exp 1 - 10
Exp2 - .
Exp 3 - 5
Exp 4 - 9
8
The MEAN function ignores missing values, so the calculation is (10+5+9)/3=8.
Which of the following SAS functions returns a number from 1 to 12?
MONTH (SAS-date-value)
The MONTH function returns the month number (1-12) extracted from a SAS date value.
In the program below, what is the value of Credit if Country is ‘au’?
data work.bonus;
set orion.sales;
if Country=’US’ then Credit=300;
else if Country=’AU’ then Credit=500;
else Credit=0;
run;
0
The character conditions are case sensitive. The first two IF conditions are false. Therefore, the final ELSE statement assigns Credit a value of zero.
What is the length of the Car_Type column created in this program?
data car_type;
set sashelp.cars;
if msrp>80000 then car_type=”luxury”;
else car_type=”regular”;
length car_type $ 8;
run;
6
When the DATA step is compiled, the first mention of Car_Type determines the column name, type, and length. The length is determined by the value in the assignment statement. The value luxury has six characters, so the length is 6.
Use a DO group in a DATA step when you want to execute multiple statements for a true IF-THEN expression.
True
To execute more that one statement if a condition is true, you must use IF-THEN/DO groups.
Which of the following pieces of information does SAS need in the DATA step in order to read an Excel workbook file and write it out to a SAS data set?
- a libref to reference the Excel workbook to be read
- the name and location (using another libref) of the new SAS data set
- the name of the Excel worksheet that is to be read
- all of the above
all of the above
- a libref to reference the Excel workbook to be read
- the name and location (using another libref) of the new SAS data set
- the name of the Excel worksheet that is to be read
To read an Excel workbook file, SAS must receive the following information in the DATA step: a libref to reference the Excel workbook to be read, the name and location (using another libref) of the new SAS data set, and the name of the Excel worksheet that is to be read.
Consider the IF-THEN statement shown When the statement is executed, which expression is evaluated first?
if finlexam>=95 and (research=’A’ or (project=’A’ and present=’A’))
then Grade=’A+’;
finlexam>=95
research=’A’
project=’A’and present=’A’
research=’A’or (project=’A’ and present=’A’)
project=’A’and present=’A’
Logical comparisons that are enclosed in parentheses are evaluated as true or false before they are compared to other expressions. In the example, the AND comparison within the nested parentheses is evaluated before being compared to the OR comparison.
For the observation shown below, what is the result of the IF-THEN statements?
Status - OK
Type - 3
Count - 12
Action - E
Control Go
if status=’OK’ and type=3
then Count = Count+1;
if status=’S’ or action=’E’
then Control=’Stop’;
Count= 13 Control = Go
Which of the following can determine the length of a new variable?
a. the length of the variable’s first value
b. the assignment statement
c. the LENGTH statement
d. all of the above
All of the above
The length of a variable is determined by its first reference in the DATA step. When creating a new character variable, SAS allocates as many bytes of storage space as there are characters in the reference to that variable. The first reference to a new variable can also be made with a LENGTH statement or an assignment statement.
Which set of statements is equivalent to the code shown below?
if code=’1’ then Type=’Fixed’;
if code=’2’ then Type=’Variable’;
if code^=’1’ and code^=’2’ then Type=’Unknown’;
if code=’1’ then Type=’Fixed’;
else if code=’2’ then Type=’Variable’;
else Type=’Unknown’;
if code=’1’ then Type=’Fixed’;
if code=’2’ then Type=’Variable’;
else Type=’Unknown’;
if code=’1’ then type=’Fixed’;
else code=’2’ and type=’Variable’;
else type=’Unknown’;
if code=’1’ and type=’Fixed’;
then code=’2’ and type=’Variable’;
else type=’Unknown’;
if code=’1’ then Type=’Fixed’;
else if code=’2’ then Type=’Variable’;
else Type=’Unknown’;
You can write multiple ELSE statements to specify a series of mutually exclusive conditions. The ELSE statement must immediately follow the IF-THEN statement in your program. An ELSE statement executes only if the previous IF-THEN/ELSE statement is false.