SAS Chapter 11: Creating And Using Macro Programs

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,578
Questions: 10 | Attempts: 1,174

SettingsSettingsSettings
SAS Chapter 11: Creating And Using Macro Programs - Quiz

Practice for the SAS advance certification exam.


Questions and Answers
  • 1. 

    Which of the following is false?

    • A.

      A %MACRO statement must always be paired with a %MEND statement.

    • B.

      A macro definition can include macro variable references, but it cannot include SAS language statements.

    • C.

      Only macro language statements are checked for syntax errors when the macro is compiled.

    • D.

      Compiled macros are stored in a temporary SAS catalog by default.

    Correct Answer
    B. A macro definition can include macro variable references, but it cannot include SAS language statements.
    Explanation
    A macro definition must begin with a %MACRO statement and must end with a %MEND statement. The macro definition can include macro language statements as well as SAS language statements. When the macro is compiled, macro language statements are checked for syntax errors. The compiled macro is stored in a temporary SAS catalog by default.

    Rate this question:

  • 2. 

    Which of the following examples correctly defines a macro named Print that includes parameters named vars and total?

    • A.

      %macro print(vars, total); proc print data=classes; var vars; sum total; run; %mend print;

    • B.

      %macro print('vars', 'total'); proc print data=classes; var &vars; sum &total; run; %mend print;

    • C.

      %macro print(vars, total); proc print data=classes; var &vars; sum &total; run; %mend print;

    • D.

      %macro print(vars, total); proc print data=classes; var :vars; sum :total; run; %mend print;

    Correct Answer
    C. %macro print(vars, total); proc print data=classes; var &vars; sum &total; run; %mend print;
    Explanation
    To include positional parameters in a macro definition, you list the parameters in parentheses and separate them with commas. When the macro is executed, macro variables will be created in the local symbol table and will have the same names as the parameters. You can then use these macro variables within the macro.

    Rate this question:

  • 3. 

    Which of the following correctly references the macro named Printdsn as shown here: %macro printdsn(dsn,vars); %if &vars= %then %do; proc print data=&dsn; title "Full Listing of %upcase(&dsn) data set"; run; %end; %else %do; proc print data=&dsn; var &vars; title "Listing of %upcase(&dsn) data set"; run; %end; %mend;

    • A.

      %printdsn(sasuser.courses, course_title days);

    • B.

      %printdsn(dsn=sasuser.courses, vars=course_title days)

    • C.

      %printdsn(sasuser.courses, course_title days)

    • D.

      %printdsn(sasuser.courses, course_title, days)

    Correct Answer
    C. %printdsn(sasuser.courses, course_title days)
    Explanation
    To call a macro that includes positional parameters, you precede the macro name with a percent sign. You list the values for the macro variables that are defined by the parameters in parentheses. List values in the same order in which the parameters are listed, and separate them with commas. Remember that a macro call is not a SAS language statement and does not require a semicolon.

    Rate this question:

  • 4. 

    If you use a mixed parameter list in your macro program definition, which of the following is false?

    • A.

      You must list positional parameters before any keyword parameters.

    • B.

      Values for both positional and keyword parameters are stored in a local symbol table.

    • C.

      Default values for keyword parameters are the values that are assigned in the macro definition, whereas positional parameters have a default value of null.

    • D.

      You can assign a null value to a keyword parameter in a call to the macro by omitting the parameter from the call.

    Correct Answer
    D. You can assign a null value to a keyword parameter in a call to the macro by omitting the parameter from the call.
    Explanation
    In a mixed parameter list, positional parameters must be listed before any keyword parameters. Both positional and keyword parameters create macro variables in the local symbol table. To assign a null value to a keyword parameter, you list the parameter without a value in the macro call.

    Rate this question:

  • 5. 

    Which of the following is false?

    • A.

      A macro program is compiled when you submit the macro definition.

    • B.

      A macro program is executed when you call it (%macro-name).

    • C.

      A macro program is stored in a SAS catalog entry only after it is executed.

    • D.

      A macro program is available for execution throughout the SAS session in which it is compiled.

    Correct Answer
    C. A macro program is stored in a SAS catalog entry only after it is executed.
    Explanation
    When you submit a macro definition, the macro is compiled and is stored in a SAS catalog. Then when you call the macro, the macro is executed. The macro is available for execution anytime throughout the current SAS session.

    Rate this question:

  • 6. 

    When you use an %IF-%THEN statement in your macro program,

    • A.

      You must place %DO and %END statements around code that describes the conditional action, if that code contains multiple statements.

    • B.

      The %ELSE statement is optional.

    • C.

      You cannot refer to DATA step variables in the logical expression of the %IF statement.

    • D.

      All of the above.

    Correct Answer
    D. All of the above.
    Explanation
    You can use %IF-%THEN statements to conditionally process code. Within a %IF-%THEN statement, you must use %DO and %END statements to enclose multiple statements. %IF-%THEN statements are similar to IF THEN statements in the DATA step, but they are part of the macro language.

    Rate this question:

  • 7. 

    Which of the following can be placed onto the input stack?

    • A.

      Only whole steps.

    • B.

      Only whole steps or whole statements.

    • C.

      Only whole statements or pieces of text within a statement.

    • D.

      Whole steps, whole statements, or pieces of text within statements.

    Correct Answer
    D. Whole steps, whole statements, or pieces of text within statements.
    Explanation
    By using %IF-%THEN statements, you can place whole steps, individual statements, or parts of statements onto the input stack.

    Rate this question:

  • 8. 

    Which of the following will create a macro variable named class in a local symbol table?

    • A.

      data _null_; set sasuser.courses; %let class=course_title; run;

    • B.

      data _null_; set sasuser.courses; call symput('class', course_title); run;

    • C.

      %macro sample(dsn); %local class; %let class=course_title; data_null_; set &dsn; run; %mend;

    • D.

      %global class; %macro sample(dsn); %let class=course_title; data _null_; set &dsn; run; %mend;

    Correct Answer
    C. %macro sample(dsn); %local class; %let class=course_title; data_null_; set &dsn; run; %mend;
    Explanation
    There are several ways to create macro variables in the local symbol table. Macro variables that are created by parameters in a macro definition or by a %LOCAL statement are always created in the local table. Macro variables that are created by a %LET statement or by the SYMPUT routine inside a macro definition might be created in the local table as well.

    Rate this question:

  • 9. 

    Which of the following examples correctly defines the macro program Hex?

    • A.

      %macro hex(start=1, stop=10, incr=1); %local i; data _null_; %do i=&start to &stop by &incr; value=&i; put "Hexadecimal form of &i is " value hex6.; %end; run; %mend hex;

    • B.

      %macro hex(start=1, stop=10, incr=1); %local i; data _null_; %do i=&start %to &stop %by &incr; value=&i; put "Hexadecimal form of &i is " value hex6.; %end; run; %mend hex;

    • C.

      %macro hex(start=1, stop=10, incr=1); %local i; data _null_; %do i=&start to &stop by &incr; value=&i; put "Hexadecimal form of &i is " value hex6.; run; %mend hex;

    • D.

      %macro hex(start=1, stop=10, incr=1); %local i; data _null_; %do i=&start to &stop by &incr; value=&i; put "Hexadeciaml form of &i is " value hex6.; %end run; %mend hex;

    Correct Answer
    B. %macro hex(start=1, stop=10, incr=1); %local i; data _null_; %do i=&start %to &stop %by &incr; value=&i; put "Hexadecimal form of &i is " value hex6.; %end; run; %mend hex;
    Explanation
    To define macros with %DO loops you use a %DO statement and a %END statement. Be sure to precede all keywords in the statements with percent signs since the %DO and %END statements are macro language statements. Also, be sure to end these statements with semicolons.

    Rate this question:

  • 10. 

    When you submit a call to a compiled macro, what happens?

    • A.

      First, the macro processor checks all macro programming statements in the macro for syntax errors. Then the macro processor executes all statements in the macro.

    • B.

      he macro processor executes compiled macro programming statements. Then any SAS programming language statements are executed by the macro processor.

    • C.

      First, all compiled macro programming statements are executed by the macro processor. After all macro statements have been processed, any SAS language statements are passed back to the input stack in order to be passed to the compiler and then executed.

    • D.

      The macro processor executes compiled macro statements. If any SAS language statements are encountered, they are passed back to the input stack. The macro processor pauses while those statements are passed to the compiler and then executed. Then the macro processor continues to repeat these steps until it reaches the %MEND statement.

    Correct Answer
    D. The macro processor executes compiled macro statements. If any SAS language statements are encountered, they are passed back to the input stack. The macro processor pauses while those statements are passed to the compiler and then executed. Then the macro processor continues to repeat these steps until it reaches the %MEND statement.
    Explanation
    When you submit a call to a compiled macro, the macro is executed. Specifically, the macro processor executes compiled macro language statements first. When any SAS language statements are encountered, the macro processor places these statements onto the input stack and pauses while they are passed to the compiler and then executed. Then the macro processor continues to repeat these steps until the %MEND statement is reached.

    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
  • Aug 21, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Mar 22, 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.