Midterm 2 (Ch 4-7) Flashcards

1
Q

In which phase does the DATA step check for syntax errors?

A

Compilation

Checking for syntax errors is the first step in the compilation phase.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Which statement is used to read a SAS data set in a DATA step?

A

SET statement

The SET statement indicates the table that will be read. The DATA statement indicates the table that will be created or updated.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

To process an Excel file with the DATA step, you must first create a copy of the data as a SAS table.

A

False

You can use the XLSX LIBNAME engine to read an Excel worksheet directly and process the data with the DATA step.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the name of the ouput data set in the program below?

data work.us;
set orion.sales;
where Country=’US’;
run;

A

work.us

The output table is listed in the DATA statement.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

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;

A

Four

Only the four columns listed in the KEEP statement are written to the work.comp table.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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

A

8

The MEAN function ignores missing values, so the calculation is (10+5+9)/3=8.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Which of the following SAS functions returns a number from 1 to 12?

A

MONTH (SAS-date-value)

The MONTH function returns the month number (1-12) extracted from a SAS date value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

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;

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

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;

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Use a DO group in a DATA step when you want to execute multiple statements for a true IF-THEN expression.

A

True

To execute more that one statement if a condition is true, you must use IF-THEN/DO groups.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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
A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

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’)

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

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’;

A

Count= 13 Control = Go

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

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

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

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’;

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the length of the variable Type, as created in the DATA step below?

data work.newloan;
set cert.records;
TotLoan+payment;
if code=’1’ then Type=’Fixed’;
else Type=’Variable’;
length type $ 10;
run;

5
8
10
It depends on the first value of Type

A

5

The length of a new variable is determined by the first reference in the DATA step, not by data values. In this case, the length of Type is determined by the value Fixed. The LENGTH statement is in the wrong place; it must occur before any other reference to the variable in the DATA step. You can run PROC CONTENTS on the data set to see the length of each variable.

17
Q

Which program contains an error?

data stresstest(drop=timemin timesec);
set cert.tests;
TotalTime=(timemin*60)+timesec;
SumSec+totaltime;
run;

proc print data=stresstest;
label totaltime=’Total Duration of Test’;
drop sumsec;
run;

proc print data=stresstest(keep=totaltime timemin);
label totaltime=’Total Duration of Test’;
run;

data stresstest;
set tests;
TotalTime=(timemin*60)+timesec;
keep id totaltime tolerance;
run;

A

data stresstest(drop=timemin timesec);
set cert.tests;
TotalTime=(timemin*60)+timesec;
SumSec+totaltime;
Run;

To select variables, you can use a DROP or KEEP statement in any DATA step. You can also use the DROP= or KEEP= data set options following a data set name in any DATA or PROC step. However, you cannot use DROP or KEEP statements in PROC steps.

18
Q

If you submit the following program, which variables appear in the new data set?

data work.cardiac(drop=age group);
set cert.fitness(keep=age weight group);
if group=2 and age>40;
run;

none
Weight
Age, Group
Age, Weight, Group

A

None

19
Q

Which of the following programs correctly reads the data set Orders and creates the data set FastOrdr?

data fastordr(drop=ordrtime);
set cert.orders(keep=product units price);
if ordrtime<4;
Total=units*price;
run;

data orders(drop=ordrtime);
set cert.fastordr(keep=product units price);
if ordrtime<4;
Total=units*price;
run;

data fastordr(drop=ordrtime);
set cert.orders(keep=product units price ordrtime);
if ordrtime<4;
Total=units*price;
run;

none of the above

A

data fastordr(drop=ordrtime);
set cert.orders(keep=product units price);
if ordrtime<4;
Total=units*price;
run;

20
Q
A