SAS練習問題集from online tutor

4060 ワード

以下はonline tutorから選んだ基礎練習問題です.一定の迷いはあるが、本題ほど難しくはないはずだ.
[size=medium]
1. Which of the following would you use to compare the result of investing $4,000 a year for five years in three different banks that compound interest monthly? Assume a fixed rate for the five-year period.
a.  DO WHILE statement
b.  nested DO loops
c.  DO UNTIL statement
d.  a DO group
Correct answer:   b
Place the monthly calculation in a DO loop within a DO loop that iterates once for each year. The DO WHILE and DO UNTIL statements are not used here because the number of required iterations is fixed. A non-iterative DO group would not be useful.
2. What is the length of the variable Type, as created in the DATA step below?

[b]data finance.newloan;
   set finance.records;
   TotLoan+payment;
   if code='1' then Type='Fixed';
   else Type='Variable';
   length type $ 10;[/b]
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 be read before any other reference to the variable in the DATA step. The LENGTH statement cannot change the length of an existing variable
3.Which program contains an error?
a.

[b]    data clinic.stress(drop=timemin timesec);
       infile tests;
       input ID $ 1-4 Name $ 6-25 RestHR 27-29 MaxHR 31-33
             RecHR 35-37 TimeMin 39-40 TimeSec 42-43
             Tolerance $ 45;
       TotalTime=(timemin*60)+timesec;
       SumSec+totaltime;
    run;[/b]

b.

[b]    proc print data=clinic.stress;
       label totaltime='Total Duration of Test';
       format timemin 5.2;
       drop sumsec;
    run;[/b]

c.

[b]    proc print data=clinic.stress(keep=totaltime timemin);
       label totaltime='Total Duration of Test';
       format timemin 5.2;
    run;[/b]

d.

[b]    data clinic.stress;
       infile tests;
       input ID $ 1-4 Name $ 6-25 RestHR 27-29 MaxHR 31-33
             RecHR 35-37 TimeMin 39-40 TimeSec 42-43
             Tolerance $ 45;
       TotalTime=(timemin*60)+timesec;
       keep id totaltime tolerance;
    run;[/b]

Correct answer:   b
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.
4. Which INPUT statement reads the values for Lname, Fname, Department and Salary (in that order)?
参照
1---+----10---+----20---
ABRAMS THOMAS
SALES $25,209.03
BARCLAY ROBERT
MARKETING $29,180.36
COURTNEY MARK
PUBLICATIONS $24,006.16
a.

[b]input #1 Lname $ Fname $ / 
      Department $12. Salary comma10.; [/b]

b.

[b]input #1 Lname $ Fname $ / 
      Department : $12. Salary : comma.;[/b]

c.

[b]input #1 Lname $ Fname $ 
      #2 Department : $12. Salary : comma.;[/b]

d. both b and c
Correct answer:  d
You can use either the/or #n line pointer control to advance the input pointer to the second line, in order to read the values for Department and Salary. The colon (:) modifier is used to read the character values that are longer than eight characters (Department) and the nonstandard data values (Salary).
[/size]