SAS Chapter 11: Creating And Using Macro Programs

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Moxleyv
M
Moxleyv
Community Contributor
Quizzes Created: 38 | Total Attempts: 21,748
| Attempts: 1,193
SettingsSettings
Please wait...
  • 1/10 Questions

    Which of the following is false?

    • A %MACRO statement must always be paired with a %MEND statement.
    • A macro definition can include macro variable references, but it cannot include SAS language statements.
    • Only macro language statements are checked for syntax errors when the macro is compiled.
    • Compiled macros are stored in a temporary SAS catalog by default.
Please wait...
About This Quiz

This quiz assesses knowledge in SAS Macro Programming, focusing on macro creation, parameter handling, and conditional statements. It tests the ability to define, reference, and utilize macros effectively, enhancing skills vital for advanced SAS programming.

SAS Chapter 11: Creating And Using Macro Programs - Quiz

Quiz Preview

  • 2. 

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

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

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

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

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

    Correct Answer
    A. %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;

    • %printdsn(sasuser.courses, course_title days);

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

    • %printdsn(sasuser.courses, course_title days)

    • %printdsn(sasuser.courses, course_title, days)

    Correct Answer
    A. %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?

    • You must list positional parameters before any keyword parameters.

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

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

    • 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
    A. 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 macro program is compiled when you submit the macro definition.

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

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

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

    Correct Answer
    A. 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,

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

    • The %ELSE statement is optional.

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

    • All of the above.

    Correct Answer
    A. 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?

    • Only whole steps.

    • Only whole steps or whole statements.

    • Only whole statements or pieces of text within a statement.

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

    Correct Answer
    A. 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?

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

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

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

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

    Correct Answer
    A. %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?

    • %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;

    • %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;

    • %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;

    • %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
    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;
    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?

    • 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.

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

    • 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.

    • 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
    A. 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 (Updated): Aug 21, 2023 +

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.