Tuesday, 12 February 2013

SAS Macro Interview Question



SAS Macro Interview Question

1. Have you used macros? For what purpose you have used?

Yes I have, I used macros in creating analysis datasets and tables where it is necessary to make a small change through out the program and where it is necessary to use the code again and again.

2. How would you invoke a macro?
After I have defined a macro I can invoke it by adding the percent sign prefix to its name like this: % macro name a semicolon is not required when invoking a macro, though adding one generally does no harm.
3. How can you create a macro variable with in data step?
with CALL SYMPUT

4. How would you identify a macro variable?
with Ampersand (&) sign

5. How would you define the end of a macro?
The end of the macro is defined by %Mend Statement

6. For what purposes have you used SAS macros?
If we want use a program step for executing to execute the same Proc step on multiple data sets. We can accomplish repetitive tasks quickly and efficiently. A macro program can be reused many times. Parameters passed to the macro program customize the results without having to change the code within the macro program. Macros in SAS make a small change in the program and have SAS echo that change thought that program.

7. What is the difference between %LOCAL and %GLOBAL?
% Local is a macro variable defined inside a macro.%Global is a macro variable defined in open code (outside the macro or can use anywhere).

8. How long can a macro variable be? A token?
A component of SAS known as the word scanner breaks the program text into fundamental units called tokens.
· Tokens are passed on demand to the compiler.
· The compiler then requests token until it receives a semicolon.
· Then the compiler performs the syntax check on the statement.

9. If you use a SYMPUT in a DATA step, when and where can you use the macro variable?
The macro variable created by the CALL SYMPUT routine cannot be used in the same datastep in which it got created. Other than that we can use the macro variable at any time..

10. What do you code to create a macro? End one?
We create a macro with %MACRO statement and end a macro with %MEND statemnt.

2 comments:

  1. Hello Nitin,
    You have included quite good question in you post for SAS macro.Bt it's not enough, please provide me with some more questions related to it

    ReplyDelete
  2. Nice Post !!!

    I have recently seen one good site for SAS interview questions and answers, Please find the link below:

    http://www.wikiconsole.com/wiki/dwh/sas/

    ReplyDelete