SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Searchback||next

Quiz: Creating Variables

Select the best answer for each question and click Score My Quiz.

  1. Suppose you need to create a variable, MaxValue, that is equal to Units times the maximum of PriceApril, PriceMay, and PriceJune. Which assignment statement will do this?

     a.   maxvalue=units**sum(PriceApr,PriceMay,PriceJun);
     b.   MaxValue=units*max(PriceApr,PriceMay,PriceJun);
     c.   maxvalue=units**mean(PriceApr,PriceMay,PriceJun);
     d.   MaxValue=units*scan(PriceApr,PriceMay,PriceJun);

  2. The assignment statement is one of the few SAS statements that does not:

     a.   begin with a keyword
     b.   end with a semicolon
     c.   support mixed-case variable names
     d.   allow the use of comparison operators

  3. Consider the small data set and program shown below. What is the value of Count after the fourth observation is read?

    SAS Data Set
    Work.Numbers
    Tens
    10
    20
    30
    40
    50
    
      data work.newnums;
         set work.numbers;
         Count+tens;
      run;

     a.   missing
     b.   0
     c.   50
     d.   100

  4. For the observation shown below, what is the result of the IF-THEN statement?

    Status Type Count Condition Control
    ok 3 12 E Go

    if status='OK' and type=3
       then count+1;
    if status='S' or condition='E'
       then control='Stop';

     a.   Count = 12    Control = Stop
     b.   Count = 12    Control = Go
     c.   Count = 13    Control = Stop
     d.   Count = 13    Control = Go

  5. Consider the IF-THEN statement shown below. When the statement is run, which expression is evaluated first?
    if mean(MidTerm,FinalExam)>=95
       and (ResearchPaper='A' or
           (Project='A' and Presentation='A'))
       then grade='A+';

     a.   mean(MidTerm,FinExam)>=95
     b.   ResearchPaper='A'
     c.   Project='A' and Presentation='A'
     d.   ResearchPaper='A' or
    (Project='A' and Presentation='A')

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

  7. Which of the following does not determine the length of a new variable?

     a.   the variable's first reference in the DATA step
     b.   the length of the variable's first value
     c.   the assignment statement
     d.   the LENGTH statement

  8. 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='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

  9. Which set of statements is equivalent to the code shown below?
    length Type $ 14;
    if code='1' and months=360 then
       type='Fixed Mortgage';
    else if code='1'
         then type='Fixed Other';
    else type='Variable';

     a.  
    length Type $ 14;
    if code='1' then
       if months=360 then
          type='Fixed Mortgage';
       else type='Fixed Other';
    else type='Variable';
     
     b.  
    length Type $ 14;
    if code='1' then
       do if months=360;
          type='Fixed Mortgage';
          else type='Fixed Other';
       end;
    else type='Variable';
     
     c.  
    length Type $ 14;
    if code='1' then
       do;
          if months=360 then
             type='Fixed Mortgage';
          else type='Fixed Other';
       end;
    else type='Variable';
     
     d.  
    length Type $ 14;
    if code='1' then
       do;
          if months=360 then
             do;
                type='Fixed Mortgage';
             end;
          type='Fixed Other';
       end;
    else type='Variable';

  10. Which version of the code will run correctly?

     a.  
    if code='1' then
       do;
          if months=360 then
             do;
                Type='Fixed Mortgage';
                note='Check current prime rate.';
          else Type='Fixed Other';
    else Type='Variable';
     
     b.  
    if code='1' then
       do;
          if months=360 then
             do;
                Type='Fixed Mortgage';
                note='Check current prime rate.';
             end;
          else Type='Fixed Other';
       end;
    else Type='Variable';
     
     c.  
    if code='1' then
       do;
          if months=360 then
                Type='Fixed Mortgage';
                note='Check current prime rate.';
             end;
          else Type='Fixed Other';
    else Type='Variable';
     
     d.  
    if code='1' then
          if months=360 then
             do;
                Type='Fixed Mortgage';
                note='Check current prime rate.';
          else Type='Fixed Other';
       end;
    else Type='Variable';



back||next

Terms of Use & Legal Information | Privacy Statement