SAS Chapter 10: Processing Macro Variables At Execution Time

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: 20,684
Questions: 10 | Attempts: 348

SettingsSettingsSettings
SAS Quizzes & Trivia

Practice for the SAS advance certification exam


Questions and Answers
  • 1. 

    Which of the following is false?

    • A.

      A %LET statement causes the macro processor to create a macro variable before the program is compiled.

    • B.

      To create a macro variable that is based on data calculated by the DATA step, you use the SYMPUT function.

    • C.

      Macro functions are always processed during the execution of the DATA step.

    • D.

      Macro variable references in a DATA step are always resolved prior to DATA step execution.

    Correct Answer
    C. Macro functions are always processed during the execution of the DATA step.
    Explanation
    Most macro functions are handled by the macro processor before any SAS language statements in the DATA step are executed. For example, the %LET statement and any macro variable references (&macvar) are passed to the macro processor before the program is compiled. In order to create or update macro variables during DATA step execution, you use the SYMPUT routine.

    Rate this question:

  • 2. 

    Which of the following correctly creates a macro variable named region and assigns to it a value that is based on the value of the data set variable Location?

    • A.

      data new; set sasuser.all; if location='Boston' then do; call symput('region', 'East'); end; else do; call symput('region', 'West'); end; run;

    • B.

      data new; set sasuser.all; if location='Boston' then do; %let region=East; end; else %let region=West; end; run;

    • C.

      data new; set sasuser.all; if location='Boston' then do; call symput(region, "East"); end; else call symput(region, "West"); end; run;

    • D.

      data new; set sasuser.all; if location='Boston' then do; symput(region, East); end; else symput(region, West); end; run;

    Correct Answer
    A. data new; set sasuser.all; if location='Boston' then do; call symput('region', 'East'); end; else do; call symput('region', 'West'); end; run;
    Explanation
    To create a macro variable and assign to it a value that is based on the value of a DATA step variable, you use the SYMPUT routine. In the SYMPUT routine, to assign a literal string as a macro variable name, you enclose the literal in quotation marks. To assign a literal string as a value of the macro variable, you enclose the literal in quotation marks.

    Rate this question:

  • 3. 

    The SYMPUT routine cannot

    • A.

      Be used to assign a data set variable as a value to a macro variable.

    • B.

      Create a series of macro variables in one DATA step.

    • C.

      Automatically convert a numeric value to a character value when used to assign a value to a macro variable in a DATA step.

    • D.

      Be used to assign a numeric value to a macro variable in an SCL program.

    Correct Answer
    D. Be used to assign a numeric value to a macro variable in an SCL program.
    Explanation
    The SYMPUT routine enables you to assign a data set variable as the value of a macro variable. You can also use the SYMPUT routine to create a series of related macro variables. Because all macro variable values are character strings, SYMPUT automatically converts any numeric value that you attempt to assign as a value for a macro variable. In an SCL program, you must use SYMPUTN rather than SYMPUT if you are attempting to assign a numeric value to a macro variable.

    Rate this question:

  • 4. 

    Which of the following programs correctly creates a series of macro variables whose names are values of the data set variableCourse_code, then indirectly references one of those macro variables in a later step?

    • A.

      data _null_; set sasuser.courses; call symput(course_code, trim(course_title)); %let crsid=C005; proc print data=sasuser.schedule noobs label; where course_code="&crsid"; var location begin_date teacher; title1 "Schedule for &c005"; run;

    • B.

      data _null_; set sasuser.courses; call symput(course_code, trim(course_title)); run; %let crsid=C005; proc print data=sasuser.schedule noobs label; where course_code="&crsid"; var location begin_date teacher; title1 "Schedule for &&&crsid"; run;

    • C.

      data _null_; set sasuser.courses; call symput('course_code', trim(course_title)); run; %let crsid=C005; proc print data=sasuser.schedule noobs label; where course_code="&crsid"; var location begin_date teacher; title1 "Schedule for &&&crsid"; run;

    • D.

      data _null_; set sasuser.courses; call symget(course_code, trim(course_title)); run; %let crsid=C005; proc print data=sasuser.schedule noobs label; where course_code="&crsid"; var location begin_date teacher; title1 "Schedule for &&&crsid"; run;

    Correct Answer
    B. data _null_; set sasuser.courses; call symput(course_code, trim(course_title)); run; %let crsid=C005; proc print data=sasuser.schedule noobs label; where course_code="&crsid"; var location begin_date teacher; title1 "Schedule for &&&crsid"; run;
    Explanation
    You can use multiple ampersands to create an indirect reference when the value of one macro variable is the name of another. If you enclose the DATA step variable name in quotation marks in the SYMPUT routine, the new macro variable will have the same name as the DATA step variable rather than having the DATA step variable's value as a name. Use the SYMGET function to obtain the value of a macro variable during the execution of a DATA step.

    Rate this question:

  • 5. 

    Which of the following statements about the resolution of macro variable references is false?

    • A.

      Two ampersands resolve to one ampersand.

    • B.

      If more than four consecutive ampersands precede a name token, the macro processor generates an error message.

    • C.

      Re-scanning continues until there are no remaining macro triggers that the macro processor can resolve.

    • D.

      The macro processor always re-scans a name token that is preceded by multiple ampersands or by multiple percent signs.

    Correct Answer
    B. If more than four consecutive ampersands precede a name token, the macro processor generates an error message.
    Explanation
    If more than four consecutive ampersands precede a name token, rescanning continues from left to right until no more triggers can be resolved. The Forward Re-scan rule describes how the macro processor resolves macro variable references that start with multiple ampersands or with multiple percent signs.

    Rate this question:

  • 6. 

    In which of the following situations would you use SYMGET rather than a macro variable reference (&macvar)?

    • A.

      To create a DATA step variable from a macro variable value during the execution of the DATA step

    • B.

      To include a macro variable reference in a PROC SQL view

    • C.

      To access the value of a macro variable during the execution of an SCL program

    • D.

      All of the above

    Correct Answer
    D. All of the above
    Explanation
    A macro variable reference (&macvar) is resolved before any SAS language statements are sent to the compiler. The SYMGET function enables you to obtain the value of a macro variable during the execution of a DATA step or a PROC SQL step. The SYMGET function can also be used to obtain the value of a macro variable during the execution of an SCL program.

    Rate this question:

  • 7. 

    Which of the following correctly creates a macro variable in a PROC SQL step?

    • A.

      Call symput(daily_fee, put(fee/days, dollar8.);

    • B.

      %let daily_fee=put(fee/days, dollar8.)

    • C.

      Select fee/days format=dollar8. into :daily_fee from sasuser.all;

    • D.

      Select fee/days format=dollar8. into daily_fee from sasuser.all;

    Correct Answer
    C. Select fee/days format=dollar8. into :daily_fee from sasuser.all;
    Explanation
    To create a macro variable during the execution of a PROC SQL step, use the INTO clause of the SELECT statement. In the INTO clause, you precede the name of the macro variable with a colon.

    Rate this question:

  • 8. 

    According to the global symbol table shown here, what value will a reference to &&teach&crs resolve to?

    • A.

      &TEACH3

    • B.

      TEACH3

    • C.

      Forest, Mr. Peter

    • D.

      None of the above

    Correct Answer
    C. Forest, Mr. Peter
    Explanation
    You can use multiple ampersands to delay the resolution of a macro variable reference. You can also combine macro variable references in order to create new tokens. In this example, the reference &&teach&crs resolves to &teach3 on the first scan. On the next scan, &teach3 resolves to Forest, Mr. Peter.

    Rate this question:

  • 9. 

    Which of the following statements correctly creates a DATA step variable named Price and assigns to it the value of the macro variabledaily_fee during DATA step execution?

    • A.

      Price=&daily_fee;

    • B.

      Price=symget(daily_fee);

    • C.

      Price=symget(&daily_fee);

    • D.

      Price=symget("daily_fee");

    Correct Answer
    D. Price=symget("daily_fee");
    Explanation
    You can use the SYMGET function in an assignment statement to obtain the current value of a macro variable and to assign that value to a DATA step variable. The SYMGET function enables you to obtain the value of a macro variable during execution of a DATA step, a PROC SQL step, or an SCL program.

    Rate this question:

  • 10. 

    Which of the following is false?

    • A.

      The SYMPUT routine can be used to create a macro variable during execution of the DATA step or during execution of an SCL program.

    • B.

      In the DATA step, the SYMPUT routine automatically converts to a character value any numeric value that you attempt to assign as the value of a macro variable.

    • C.

      PROC SQL automatically converts to a numeric value any macro variable value that you attempt to compare to a numeric value.

    • D.

      In an SCL program, the SYMPUTN routine can be used to assign a numeric value to a macro variable.

    Correct Answer
    C. PROC SQL automatically converts to a numeric value any macro variable value that you attempt to compare to a numeric value.
    Explanation
    The SYMPUT routine can be used in either the DATA step or in an SCL program. In the DATA step, the SYMPUT routine will perform automatic conversion on numeric values that you attempt to assign as values for macro variables, using the BEST12. format. In an SCL program, you should use the SYMPUTN routine if you want to assign a numeric value as a value for a macro variable. In a PROC SQL step, you need to use the INPUT function in order to convert macro variable values to numeric before you compare them to other numeric values.

    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 17, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Mar 18, 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.