SAS Chapter 14

10 Questions | Attempts: 224
Share

SettingsSettingsSettings
SAS Quizzes & Trivia

Practice for the SAS base certification exam.


Questions and Answers
  • 1. 

    Which function calculates the average of the variables Var 1, Var 2, Var 3, and Var 4?

    • A.

      Mean(var1,var4)

    • B.

      Mean(var1-var4)

    • C.

      Mean(of var1,var4)

    • D.

      Mean(of var1-var4)

    Correct Answer
    D. Mean(of var1-var4)
    Explanation
    Use a variable list to specify a range of variables as the function argument. When specifying a variable list, be sure to precede the list with the word OF. If you omit the word OF, the function argument might not be interpreted as expected.

    Rate this question:

  • 2. 

    Within the data set Hrd.Temp, PayRate is a character variable and Hours is a numeric variable.  What happens when the following program is run? data work.temp;    set hrd.temp;    Salary=payrate*hours; run;

    • A.

      SAS converts the values of PayRate to numeric values. No message is written to the log.

    • B.

      SAS converts the values of Payrate to numeric values.  A message is written to the log.

    • C.

      SAS converts the values of Hours to character values.  No message is written to the log.

    • D.

      SAS converts the values of Hours to character values. A message is written to the log.

    Correct Answer
    B. SAS converts the values of Payrate to numeric values.  A message is written to the log.
    Explanation
    When this DATA step is executed, SAS automatically converts the character values of PayRate to numeric values so that the calculation can occur. Whenever data is automatically converted, a message is written to the SAS log stating that the conversion has occurred.

    Rate this question:

  • 3. 

    A typical value for the character variable Target is 123,456.  Which statement correctly converts the values of Target to numeric values when creating the variable TargetNo?

    • A.

      TargetNo=input(target,comma6.);

    • B.

      TargetNo=input(target,comma7.);

    • C.

      TargetNo=put(target,comma6.);

    • D.

      TargetNo=(target,comma7.)

    Correct Answer
    B. TargetNo=input(target,comma7.);
    Explanation
    You explicitly convert character values to numeric values by using INPUT function. Be sure to select an informat that can read the form of the values.

    Rate this question:

  • 4. 

    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. Location=dept||'/'||put(sitenum,4.1);
    Explanation
    You explicitly convert numeric values to character values by using the PUT function. Be sure to select a format that can read the form of the values.

    Rate this question:

  • 5. 

    Suppose the YEARCUTOFF= system option is set to 1920.  Which MDY function creates the date value for January 3, 2020?

    • A.

      MDY(1,3,20)

    • B.

      MDY(3,1,20)

    • C.

      MDY(1,3,2020)

    • D.

      MDY(3,1,2020)

    Correct Answer
    C. MDY(1,3,2020)
    Explanation
    Because the YEARCUTOFF= system option is set to 1920, SAS sees the two-digit year value 20 as 1920. Four-digit year values are always read correctly.

    Rate this question:

  • 6. 

    The variable Address2 contains values such as Piscataway, NJ.  How do you assign the two-letter state abbreviations to a new variable named State?

    • A.

      State=scan(address2,2);

    • B.

      State=scan(address2,13,2);

    • C.

      State=substr(address2,2);

    • D.

      State=substr(address2,13,2);

    Correct Answer
    A. State=scan(address2,2);
    Explanation
    The SCAN function is used to extract words from a character value when you know the order of the words, when their position varies, and when the words are marked by some delimiter. In this case, you don't need to specify delimiters, because the blank and the comma are default delimiters.

    Rate this question:

  • 7. 

    The variable IDCode contains values such as 123FA and 321MB.  The fourth character identifies sex.  How do you assign these character codes to a new variable named Sex?

    • A.

      Sex=scan(idcode,4);

    • B.

      Sex=scan(idcode,4,1);

    • C.

      Sex=substr(idcode,4);

    • D.

      Sex=substr(idcode,4,1);

    Correct Answer
    D. Sex=substr(idcode,4,1);
    Explanation
    The SUBSTR function is best used when you know the exact position of the substring to extract from the character value. You specify the position to start from the number of characters to extract.

    Rate this question:

  • 8. 

    Due to the growth within the 919 area code, the telephone exchange 555 is being reassigned to the 920 area code.  The data set Clients.Piedmont includes the variable Phone, which contains telephone numbers in the form 919-555-1234.  Which of the following programs will correctly change the values of Phone?

    • A.

      Data work.piedmont(drop=areacode exchange);    set clients.piedmont;    Areacode=substr(phone,1,3);    Exchange=substr(phone,5,3);    if areacode='919' and exchange='555'       then scan(phone,1,3)='920'; run;

    • B.

      Data work.piedmont(drop=areacode exchange);    set clients.piedmont;    Areacode=substr(phone,1,3);    Exchange=substr(phone,5,3);    if areacode='919' and exchange='555'       then phone=scan('920',1,3); run;

    • C.

      Data work.piedmont(drop=areacode exchange);    set clients.piedmont;    Areacode=substr(phone,1,3);    Exchange=substr(phone,5,3);    if areacode='919' and exchange='555'       then substr(phone,5,3)='920'; run;

    • D.

      Data work.piedmont(drop=areacode exchange);    set clients.piedmont;    Areacode=substr(phone,1,3);    Exchange=substr(phone,5,3);    if areacode='919' and exchange='5555'

    Correct Answer
    C. Data work.piedmont(drop=areacode exchange);    set clients.piedmont;    Areacode=substr(phone,1,3);    Exchange=substr(phone,5,3);    if areacode='919' and exchange='555'       then substr(phone,5,3)='920'; run;
    Explanation
    The SUBSTR function replaces variable values if it is placed on the left side of an assignment statement. When placed on the right side (as in Question 7), the function extracts a substring.

    Rate this question:

  • 9. 

    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 reatil.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. Data work.maillist;    set retail.maillist;    length FullName $ 40;    fullname=trim(firstname)||' '||lastname; run;
    Explanation
    The TRIM function removes trailing blanks from character values. In this case, extra blanks must be removed from the values of FirstName. Although answer c also works, the extra TRIM function for the variable LastName is unnecessary. Because of the Length statement, all values of FullName are padded to 40 characters.

    Rate this question:

  • 10. 

    Within the data set Furnitur.Bookcase, the variable Finish contains values such as ash/cherry/teak/matte-black.  Which of the follwoing creates a subset of the data in which the values of Finish contain the string walnut?  Make the search for the string case-insensitive.

    • A.

      Data work.bookcase;    set furnitur.bookcase;    if index(finish,walnut) = 0; run;

    • B.

      Data work.bookcase;    set furnitur.bookcase;    if index(finish,'walnut') = 0; run;

    • C.

      Data work.bookcase;    set furnitur.bookcase;    if index(lowcase(finish),walnut) = 0; run;

    • D.

      Data work.bookcase;    set furnitur.bookcase;    if index(lowcase(finish),'walnut') > 0; run;

    Correct Answer
    D. Data work.bookcase;    set furnitur.bookcase;    if index(lowcase(finish),'walnut') > 0; run;
    Explanation
    Use the INDEX function in a subsetting IF statement, enclosing the character string in quotation marks. Only those observations in which the function locates the string and returns a value greater than 0 are written to the data set.

    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 09, 2013
    Quiz Edited by
    ProProfs Editorial Team
  • Feb 08, 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.