SAS Macro Interview Questions & Answers

  1. Question 1. Have You Used Macros? For What Purpose You Have Used?

    Answer :

    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. Question 2. How Would You Invoke A Macro?

    Answer :

    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. SAS Programming Interview Questions

  4. Question 3. How Can You Create A Macro Variable With In Data Step?

    Answer :

    With CALL SYMPUT.

  5. Question 4. How Would You Identify A Macro Variable?

    Answer :

    With Ampersand (&) sign.

  6. SAS Programming Tutorial

  7. Question 5. How Would You Define The End Of A Macro?

    Answer :

    The end of the macro is defined by %Mend Statement.

  8. Logistics Interview Questions

  9. Question 6. For What Purposes Have You Used Sas Macros?

    Answer :

    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.

  10. Question 7. What Is The Difference Between %local And %global?

    Answer :

    % 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).

  11. SASS (Syntactically Awesome Style sheets) Tutorial
    SAS Programming,SQL server Interview Questions

  12. Question 8. How Long Can A Macro Variable Be? A Token?

    Answer :

    • 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.
  13. Question 9. If You Use A Symput In A Data Step, When And Where Can You Use The Macro Variable?

    Answer :

    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.

  14. SASS (Syntactically Awesome Style sheets) Interview Questions

  15. Question 10. What Do You Code To Create A Macro?

    Answer :

    We create a macro with %MACRO statement and end a macro with %MEND statemnt.

  16. R Programming language Tutorial

  17. Question 11. What Is The Difference Between %put And Symbolgen?

    Answer :

    %PUT is used to display user defined messages on log window after execution of a program where as % SYMBOLGEN is used to print the value of a macro variable resolved, in log window.

  18. SQL Server Analysis Services (SSAS) Interview Questions

  19. Question 12. How Do You Add A Number To A Macro Variable?

    Answer :

    Using %eval function or %sysevalf function if the number is a floating number.

  20. SAS Programming Interview Questions

  21. Question 13. Can You Execute A Macro Within A Macro? Describe.

    Answer :

    Yes, Such macros are called nested macros. They can be obtained by using symget and call symput macros.

  22. Question 14. If You Need The Value Of A Variable Rather Than The Variable Itself What Would You Use To Load The Value To A Macro Variable?

    Answer :

    If we need a value of a macro variable then we must define it in such terms so that we can call them everywhere in the program. Define it as Global. There are different ways of assigning a global variable. Simplest method is %LET.

    Ex:

    A, is macro variable. Use following statement to assign the value of a rather than the variable itself

    %Let A=xyz; %put x=”&A”;

    This will assign “xyz” to x, not the variable xyz to x.

  23. Question 15. Can You Execute Macro Within Another Macro? If So, How Would Sas Know Where The Current Macro Ended And The New One Began?

    Answer :

    Yes, I can execute macro within a macro, we call it as nesting of macros, which is allowed, Every macro’s beginning is identified the keyword %macro and end with %mend.

  24. R Programming language Interview Questions

  25. Question 16. How Would You Code A Macro Statement To Produce Information On The Sas Log?
    This Statement Can Be Coded Anywhere?

    Answer :

    OPTIONS MPRINT MLOGIC MERROR SYMBOLGEN.

  26. Question 17. How We Can Call Macros With In Data Step?

    Answer :

    We can call the macro with

    CALL SYMPUT,

    Proc SQL ,

    %LET statement. and macro parameters.

  27. SAS DI Interview Questions

  28. Question 18. Tell Me About % Include And % Eval?

    Answer :

    The %include statement, despite its percent sign, is not a macro statement and is always executed in SAS, though it can be conditionally executed in a macro.It can be used to setting up a macro library. But this is a least approach.

    The use of %include does not actually set up a library. The %include statement points to a file and when it executed the indicated file (be it a full program, macro definition, or a statement fragment) is inserted into the calling program at the location of the call.

    When using the %include building a macro library, the included file will usually contain one or more macro definitions.%EVAL is a widely used yet frequently misunderstood SAS(r) macro language function due to its seemingly simple form.

    However, when its actual argument is a complex macro expression interlaced with special characters, mixed arithmetic and logical operators, or macro quotation functions, its usage and result become elusive and problematic. %IF condition in macro is evaluated by %eval, to reduce it to true or false.

  29. Logistics Interview Questions

  30. Question 19. Describe The Ways In Which You Can Create Macro Variables?

    Answer :

    There are the 5 ways to create macro variables:

    1. %Let
    2. %Global
    3. Call Symput
    4. Proc SQl into clause
    5. Macro Parameters.
  31. Question 20. Tell Me More About The Parameters In Macro?

    Answer :

    Parameters are macro variables whose value you set when you invoke a macro. To add the parameters to a macro, you simply name the macro vars names in parenthesis in the %macro statement.

    Syntax:

    %MACRO macro-name (parameter-1= , parameter-2= , ……parameter-n = );

    macro-text%;

    %MEND macro-name;

    %macro_name(par1,par2,….parn);

  32. Advanced SAS Interview Questions

  33. Question 21. What Is The Maximum Length Of The Macro Variable?

    Answer :

    32 characters long.

  34. Question 22. Automatic Variables For Macro?

    Answer :

    Every time we invoke SAS, the macro processor automatically creates certain macro var.

    eg: &sysdate &sysday.

  35. Question 23. What System Options Would You Use To Help Debug A Macro?

    Answer :

    The SAS System offers users a number of useful system options to help debug macro issues and problems. The results associated with using macro options are automatically displayed on the SAS Log.

    Specific options related to macro debugging appear in alphabetical order in the table below:

    MEMRPT: Specifies that memory usage statistics be displayed on the SAS Log.

    MERROR: SAS will issue warning if we invoke a macro that SAS didn’t find. Presents Warning Messages when there are misspellings or when an undefined macro is called.

    SERROR: SAS will issue warning if we use a macro variable that SAS can’t find.

    MLOGIC: SAS prints details about the execution of the macros in the log.

    MPRINT: Displays SAS statements generated by macro execution are traced on the SAS Log for debugging purposes.

    SYMBOLGEN: SAS prints the value of macro variables in log and also displays text from expanding macro variables to the SAS Log.

  36. Base Sas Interview Questions

  37. Question 24. What Are Symget And Symput?

    Answer :

    SYMPUT puts the value from a dataset into a macro variable where as SYMGET gets the value from the macro variable to the dataset.

  38. SAS Programming,SQL server Interview Questions

  39. Question 25. What Is Auto Call Macro And How To Create A Auto Call Macro? What Is The Use Of It? How To Use It In Sas With Macros?

    Answer :

    SAS Enables the user to call macros that have been stored as SAS programs.

    The auto call macro facility allows users to access the same macro code from multiple SAS programs. Rather than having the same macro code for in each program where the code is required, with an autocall macro, the code is in one location. This permits faster updates and better consistency across all the programs.Macro set-up:The fist step is to set-up a program that contains a macro, desired to be used in multiple programs. Although the program may contain other macros and/or open code, it is advised to include only one macro.

    Set MAUTOSOURSE and SASAUTOS:

    Before one can use the autocall macro within a SAS program, The MAUTOSOURSE option must be set open and the SASAUTOS option should be assigned. The MAUTOSOURSE option indicates to SAS that the autocall facility is to be activated. The SASAUTOS option tells SAS where to look for the macros.

    For ex: sasauto=’g:busmeasinternalmacro’.