SAS Chapter 11 Creating And Managing Variables

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Moxleyv
M
Moxleyv
Community Contributor
Quizzes Created: 38 | Total Attempts: 21,441
Questions: 10 | Attempts: 423

SettingsSettingsSettings
SAS Chapter 11 Creating And Managing Variables - Quiz

Practice for the SAS basic certification exam.


Questions and Answers
  • 1. 

    Which program creates the output shown below?

    • A.

      Data test2;    infile furnture;    input StockNum $ 1-3 Finish $ 5-9 Style $ 11-18          Item $ 20-24 Price 26-31    if finish='oak' then delete;    retain TotPrice 100;    totalprice+price;    drop price; run; proc print data=test2 noobs; run;

    • B.

      Data test2;    infile furnture;    input StockNum $ 1-3 Finish $ 5-9 Style $ 11-18          Item $ 20-24 Price 26-31    if finish='oak' and price<200 then delete;    totalprice+price; run; proc print data=test2 noobs; run;

    • C.

      Data test2(drop=price);    infile furnture;    input StockNum $ 1-3 Finish $ 5-9 Style $ 11-18          Item $ 20-24 Price 26-31    if finish='oak' and price<200 then delete;    totalprice+price; run; proc print data=test2 noobs; run;

    • D.

      Data test2;    infile furnture;    input StockNum $ 1-3 Finish $ 5-9 Style $ 11-18          Item $ 20-24 Price 26-31    if finish='oak' and price<200 then delete;    totalprice+price; run; proc print data=test2 noobs; run;

    Correct Answer
    C. Data test2(drop=price);    infile furnture;    input StockNum $ 1-3 Finish $ 5-9 Style $ 11-18          Item $ 20-24 Price 26-31    if finish='oak' and price<200 then delete;    totalprice+price; run; proc print data=test2 noobs; run;
    Explanation
    Program c correctly deletes the observation in which the value of Finish is oak and the value of Price is less than 200. It also creates TotalPrice by summing the variable Price down observations, then drops Price by using the DROP= data set option in the DATA statement.

    Rate this question:

  • 2. 

    How is the variable Amount labeled and formatted in the PROC PRINT output? data credit;    infile creddata;    input Account $ 1-5 Name $ 7-25 Type $27              Transact $ 29-35 Amount 37-50;    label amount='Amount of Loan';    format amount dollar 12.2; run; proc print data=credit label;    label amount='Total Amount Loaned';    format amount comma10.; run;

    • A.

      Label Amount of Loan, format DOLLAR12.2

    • B.

      Label Total Amount Loaned, format COMMA10.

    • C.

      Label Amount, default format

    • D.

      The PROC PRINT step does not execute because two labels and two formats are assigned to the same variable.

    Correct Answer
    B. Label Total Amount Loaned, format COMMA10.
    Explanation
    The variable Amount is labeled as "Total Amount Loaned" and formatted as "COMMA10." in the PROC PRINT output.

    Rate this question:

  • 3. 

    Consider the IF-THEN statement shown below.  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+';

    • A.

      Finlexam>=95

    • B.

      Research='A'

    • C.

      Project='A' and present='A'

    • D.

      Research='A' or (project='A' and present='A')

    Correct Answer
    C. Project='A' and present='A'
    Explanation
    Logical comparisons that are enclosed in parenthesis are evaluated as true or false before they are compared to other expressions. In the example above, the AND comparison within the nested parenthesis is evaluated before being compared to the OR comparison.

    Rate this question:

  • 4. 

    Consider the small raw data file and program shown below.  What is the value of Count after the fourth record is read?

    • A.

      Missing

    • B.

      0

    • C.

      30

    • D.

      70

    Correct Answer
    D. 70
    Explanation
    The sum statement adds the result of the expression that is on the right side of the plus sign to the numeric variable that is on the left side. The new value is then retained for subsequent observations. The sum statement treats the missing value as a 0, so the value of Count in the fourth observation would be 10+20+0+40, or 70.

    Rate this question:

  • 5. 

    Now consider the revised program below.  What is the value of Count after the third observation is read?

    • A.

      Missing

    • B.

      0

    • C.

      100

    • D.

      130

    Correct Answer
    D. 130
    Explanation
    The RETAIN statement assigns an initial value of 100 to the variable Count, so the value of Count in the third observation would be 100+10+20+0, or 130.

    Rate this question:

  • 6. 

    For the observation show below, what is the result of the IF-THEN statements? if status='OK' and type=3    then Count+1; if status='S' or action='E'    then Control='Stop';

    • A.

      Count = 12 Control = Go

    • B.

      Count = 13 Control = Stop

    • C.

      Count = 12 Control = Stop

    • D.

      Count = 13 Control = Go

    Correct Answer
    C. Count = 12 Control = Stop
    Explanation
    You must enclose character values in quotation marks, and you must specify them in the same case in which they appear in the data set. The value ok is not identical to OK, so the value of Count i snot changed by the IF-THEN statement.

    Rate this question:

  • 7. 

    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

    Correct Answer
    D. All of the above
    Explanation
    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 first value that it encounters for that variable. The first reference to a new variable can also be made with a LENGTH statement or an assignment statement. The length of the variable's first value does not matter once the variable has been referenced in your program.

    Rate this question:

  • 8. 

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

    • A.

      If code='1' then Type='Fixed'; else if code='2' then Type='Variable'; else Type='Unknown';

    • B.

      If code='1' then Type='Fixed'; if code='2' then Type='Variable'; else Type='Unknown';

    • C.

      If code='1' then type='Fixed'; else code='2' and type='Variable'; else type='Unknown';

    • D.

      If code='1' and type='Fixed'; then code='2' and type='Variable'; else type='Unknown';

    Correct Answer
    A. If code='1' then Type='Fixed'; else if code='2' then Type='Variable'; else Type='Unknown';
    Explanation
    You can write multiple ELSE statements to specify a series of mutually exclusive conditions. The ELSE statement must follow the IF-THEN statement in your program. An ELSE statement executes only if the previous IF-THEN/ELSE statement is false.

    Rate this question:

  • 9. 

    What is the length of the variable Type, as created in the DATA step below? data finance.records;    set finance.records;    TotLoan+payment;    if code='1' 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. 5
    Explanation
    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.

    Rate this question:

  • 10. 

    Which program contains an error?

    • A.

      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.

      Proc print data=clinic.stress;    label totaltime='Total Duration of Test';    format timemin 5.2;    drop sumsec; run;

    • C.

      Proc print data=clinic.stress(keep=totaltime timemin);    label totaltime='Total Duration of Test';    format timemin 5.2; run;

    • D.

      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;

    Correct Answer
    B. Proc print data=clinic.stress;    label totaltime='Total Duration of Test';    format timemin 5.2;    drop sumsec; run;
    Explanation
    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.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 21, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Jan 30, 2013
    Quiz Created by
    Moxleyv

Related Topics

Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.