Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
71 views11 pages

ST521 Practice FinalKeyV3

This practice final exam for ST521 contains 19 multiple choice questions testing knowledge of SAS programming concepts like SQL statements, IF/THEN logic, debugging with PUTLOG, and using ARRAY statements. It also includes questions about PROC FREQ output, merging data sets, and reading formatted data records using INPUT statements.

Uploaded by

Peter Huang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views11 pages

ST521 Practice FinalKeyV3

This practice final exam for ST521 contains 19 multiple choice questions testing knowledge of SAS programming concepts like SQL statements, IF/THEN logic, debugging with PUTLOG, and using ARRAY statements. It also includes questions about PROC FREQ output, merging data sets, and reading formatted data records using INPUT statements.

Uploaded by

Peter Huang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

ST521-Practice Final Exam

1. True False Only one SQL statement may be executed within a PROC SQL step.

2. True False IF/THEN statements are used for iterative processing.

3. True False The PUTLOG statement can be useful for debugging programs.

4. True False The ARRAY statement is ignored during datastep execution.

5. True False A macro variable can contain either character or numeric data.

6. True False By default, the OUTPUT statement writes to only the first data set listed in
the DATA statement.

7. By default, PROC FREQ creates a table of frequencies and percentages for which data set
variables?
a. character variables
b. numeric variables
c. both character and numeric variables
d. none: variables must always be specified
Correct Answer: c. By default, PROC FREQ creates a table for all variables in a data set.
8. Which PROC FREQ step produced this two-way table?

a)
proc freq data=clinic.diabetes;
tables height weight;
format height htfmt. weight wtfmt.;
run;

b)
proc freq data=clinic.diabetes;
tables weight height;
format weight wtfmt. height htfmt.;
run;

c)
proc freq data=clinic.diabetes;
tables height*weight;
format height htfmt. weight wtfmt.;
run;

d)
proc freq data=clinic.diabetes;
tables weight*height;
format weight wtfmt. height htfmt.;
run;
Correct Answer: d. An asterisk is used to join the variables in a two-way TABLES
statement. The first variable forms the table rows and the second variable forms the table
columns.

9. Which of the following can determine the length of a new variable?


a) The length of the variable’s first reference in the DATA step
b) The assignment statement
c) The LENGTH statement
d) All of the above
Correct Answer: d.

10. What is the length of the variable Type, as created in the DATA step below?
data finance.newloan;
set finance.records;
TotLoan+payment;
if code='l' then Type='Fixed';
else Type='Variable';
length type $ 10;
run;

a) 5
b) 8
c) 10
d) it depends on the first value of Type
Correct Answer: a. 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.
11. At the start of DATA step processing, during the compilation phase, variables are created in
the program data vector (PDV), and observations are set to:
a. blank
b. missing
c. 0
d. there are no observations
Correct answer: d. There are no observations because the data step has not yet executed

12. A typical value for the numeric variable SiteNum is 12. 3. Which statement correctly
converts the values of SiteNum to character values when creating the variable Location?
a. Location=dept || '/' || input(sitenum, 3.1);
b. Location=dept || '/' || input(sitenum, 4.1);
c. Location=dept || '/' || put (sitenum, 3.1);
d. Location=dept || '/' || put(sitenum, 4.1);
Correct answer: d. You explicitly convert numeric values to character vales by using the
PUT function. Be sure to select a format that can read the form of the values. Here the
numeric value has a length of 4 which includes 1 decimal position.

13. Suppose you merge data sets Health.Set1 and Health.Set2 below:
ID Sex Age ID Height Weight
1129 F 48 1129 61 137
1274 F 50 1387 64 142
1387 F 57 2304 61 102
2304 F 16 5438 62 168
2486 F 63 6488 64 154
4425 F 48 9012 63 157
4759 F 60 9125 64 159
5438 F 42
6488 F 59
9012 F 39
9125 F 56

Which output does the following program create?


data work.merged;
merge health.set1(in=in1) health.set2(in=in2);
by ID;
if in1 and in2;
run;
proc print data=work.merged;
run;

a)
Obs ID Sex Age Height Weight
1 1129 F 48 61 137
2 1274 F 50 . .
3 1387 F 57 64 142
4 2304 F 16 61 102
5 2486 F 63 . .
6 4425 F 48 . .
7 4759 F 60 . .
8 5438 F 42 62 168
9 6488 F 59 64 154
10 9012 F 39 63 157
11 9125 F 56 64 159

b)
Obs ID Sex Age Height Weight
1 1129 F 48 61 137
2 1387 F 57 64 142
3 2304 F 16 61 102
4 5438 F 42 62 168
5 6488 F 59 64 154
6 9012 F 39 63 157
7 9125 F 56 64 159
8 5438 F 42 . .
9 6488 F 59 . .
10 9012 F 39 . .
11 9125 F 56 . .
c)
Obs ID Sex Age Height Weight
1 1129 F 48 61 137
2 1387 F 57 64 142
3 2304 F 16 61 102
4 5438 F 42 62 168
5 6488 F 59 64 154
6 9012 F 39 63 157
7 9125 F 56 64 159

d) none of the above


Correct answer: c. The datastep uses the IN= data set option and the subsetting IF
statement to exclude unmatched observations from the output data set. So a and b,
which contain unmatched observations, are incorrect.

14. Select the DO WHILE statement that would generate the same result as the program below.
data work.invest; capital=100000;
do until(Capital gt 500000);
Year+1;
capital+(capital*.10);
end;
run;
a. do while (Capital ge 500000); c. do while (Capital le 500000);

b. do while (Capital=500000); d. do while (Capital>500000);

Correct answer: c. Because the DO WHILE loop is evaluated at the top of the loop, you
specify the condition that must exist in order to execute then enclosed statements.

15. Suppose you need to create the variable FullName by concatenating the values of
FirstName, which contains first names, and LastName, which contains last names. What's the
best way to remove extra blanks between first names and last names?
a)
data work.maillist;
set retail.maillist;
length FullName $ 40;
fullname=trim firstname ||' '|| lastname;
run;
b)
data work.maillist;
set retail.maillist;
length FullName $ 40;
fullname=trim(firstname) ||' '|| lastname;
run;
c)
data work.maillist;
set retail.maillist;
length FullName $ 40;
fullname=trim(firstname) ||' '|| trim(lastname);
run;

d)
data work.maillist;
set retail.maillist;
length FullName $ 40;
fullname=trim(firstname ||' '|| lastname);
run;

Correct answer: b. In this example, the LENGTH statement will take care of the trailing
spaces, so example b is the most efficient.
16. Which DO statement would not process all the elements in the factors array shown below?
array factors{*} age height weight bloodpr;

a) DO i=1 to dim(factors);
b) DO i=1 to dim(*);
c) DO i=1,2,3,4;
d) DO i=1 to 4;
Correct answer: b.

17. Finish the ARRAY statement below to create temporary array elements that have initial
values of 9000, 9300, 9600, and 9900.
array goal{4} . . . ;

a) _temporary_ (9000 9300 9600 9900)


b) temporary (9000 9300 9600 9900)
c) _temporary 9000 9300 9600 9900
d) (temporary) 9000 9300 9600 9900

Correct answer: a.

18. Which pointer control is used to read multiple records sequentially?


a) @n
b) +n
c) /
d) all of the above
Correct answer: a.

19. Which SAS statement correctly reads the values for Fname, Lname, Address, City, State and
Zip in order?
1---+----10---+----20---
LAWRENCE CALDWELL
1010 LAKE STREET
ANAHEIM CA 94122
RACHEL CHEVONT
3719 OLIVE VIEW ROAD
HARTFORD CT 06183
a)
input Fname $ Lname $ /
Address $20. /
City $ State $ Zip $;
b)
input Fname $ Lname $ /;
Address $20. /;
City $ State $ Zip $;
c)
input / Fname $ Lname $
/ Address $20.
City $ State $ Zip $;
d)
input / Fname $ Lname $ ;
/ Address $20. ;
City $ State $ Zip $;
Correct answer: a.
20. Which SAS program reads the values for ID and holds the record for each value of Quantity,
so that three observations are created for each record?
1---+----10---+----20---+----30
2101 21,208 19,047 22,890
2102 18,775 20,214 22,654
2103 19,763 22,927 21,862
a) c)
data work.sales; data work.sales;
infile unitsold; infile unitsold;
input ID $; input ID $ @;
do week=1 to 3; do week=1 to 3;
input Quantity : comma. ; input Quantity : comma. ;
output; output;
end; end;
run; run;
b) d)
data work.sales; data work.sales;
infile unitsold; infile unitsold;
input ID $ @@; input ID $ @;
do week=1 to 3 ; do week=1 to 3;
input Quantity : comma.; input Quantity : comma. @;
output; output;
end; end;
run; run;

Correct answer: d.
21. Which option below, when used in a DATA step, writes an observation to the data set
after each value for Activity has been read?
a) c)
do choice=1 to 3; do choice=1 to 3;
input Activity : $10. @; input Activity $10. @;
output; end;
end; run;
run;
b) d)
do choice=1 to 3; both a and b
input Activity $10. @;
end;
output;
run;

Correct answer: a. The OUTPUT statement must be in the loop so that each time a value
for Activity is read, an observation is immediately written to the data set.
22. What data manipulation task is commonly done using either PROC TRANSPOSE or array
processing?
Answer: Reshaping data from long to wide ( or wide to long ).

23. Give a few examples of how lookup tables may be stored.


Answer: Arrays, in a SAS dataset, using SQL.

You might also like