Top 25 Sas Macro Interview Questions
Q1. What Is The Difference Between %placed And Symbolgen?
%PUT is used to display user described messages on log window after execution of a software where as % SYMBOLGEN is used to print the cost of a macro variable resolved, in log window.
Q2. Tell Me About % Include And % Eval?
The %encompass declaration, regardless of its percent sign, isn't always a macro assertion and is always completed in SAS, although it could be conditionally finished in a macro.It may be used to putting in a macro library. But this is a least approach.
The use of %encompass does not surely set up a library. The %encompass announcement points to a record and when it carried out the indicated report (be it a complete program, macro definition, or a declaration fragment) is inserted into the calling application on the place of the call.
When the usage of the %consist of constructing a macro library, the covered file will normally include one or greater macro definitions.%EVAL is a extensively used yet frequently misunderstood SAS(r) macro language characteristic because of its seemingly simple shape.
However, whilst its actual argument is a complicated macro expression interlaced with unique characters, combined mathematics and logical operators, or macro citation capabilities, its usage and end result turn out to be elusive and tricky. %IF situation in macro is evaluated by %eval, to reduce it to genuine or fake.
Q3. Automatic Variables For Macro?
Every time we invoke SAS, the macro processor routinely creates positive macro var.
Eg: &sysdate &sysday.
Q4. What Is The Difference Between %nearby And %global?
% Local is a macro variable described internal a macro.%Global is a macro variable described in open code (outdoor the macro or can use anywhere).
Q5. Tell Me More About The Parameters In Macro?
Parameters are macro variables whose price you set whilst you invoke a macro. To add the parameters to a macro, you in reality call the macro vars names in parenthesis inside the %macro statement.
Syntax:
%MACRO macro-name (parameter-1= , parameter-2= , ……parameter-n = );
macro-text%;
%MEND macro-call;
%macro_name(par1,par2,....Parn);
Q6. How Can You Create A Macro Variable With In Data Step?
With CALL SYMPUT.
Q7. What System Options Would You Use To Help Debug A Macro?
The SAS System gives users a number of beneficial device options to help debug macro troubles and problems. The effects associated with the usage of macro alternatives are automatically displayed at the SAS Log.
Specific alternatives associated with macro debugging appear in alphabetical order in the table under:
MEMRPT: Specifies that memory usage facts be displayed on the SAS Log.
MERROR: SAS will issue caution if we invoke a macro that SAS didn’t discover. Presents Warning Messages when there are misspellings or while an undefined macro is known as.
SERROR: SAS will problem warning if we use a macro variable that SAS can’t find.
MLOGIC: SAS prints information about the execution of the macros within the log.
MPRINT: Displays SAS statements generated by means of macro execution are traced on the SAS Log for debugging functions.
SYMBOLGEN: SAS prints the cost of macro variables in log and additionally displays text from expanding macro variables to the SAS Log.
Q8. 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?
If we need a cost of a macro variable then we need to outline it in such terms in order that we will name them everywhere inside the program. Define it as Global. There are different methods of assigning a international variable. Simplest approach is %LET.
Ex:
A, is macro variable. Use following assertion to assign the cost of a in place of the variable itself
%Let A=xyz; %positioned x="&A";
This will assign "xyz" to x, no longer the variable xyz to x.
Q9. For What Purposes Have You Used Sas Macros?
If we need use a software step for executing to execute the equal Proc step on multiple data units. We can accomplish repetitive obligations fast and efficaciously. A macro application may be reused often. Parameters surpassed to the macro application personalize the outcomes while not having to trade the code within the macro software. Macros in SAS make a small change in the software and have SAS echo that exchange idea that program.
Q10. Have You Used Macros? For What Purpose You Have Used?
Yes I actually have, I used macros in creating analysis datasets and tables wherein it's miles vital to make a small alternate thru out the program and where it's far necessary to apply the code time and again.
Q11. Can You Execute Macro Within Another Macro? If So, How Would Sas Know Where The Current Macro Ended And The New One Began?
Yes, I can execute macro inside a macro, we call it as nesting of macros, that is allowed, Every macro's beginning is diagnosed the key-word %macro and end with %mend.
Q12. How We Can Call Macros With In Data Step?
We can call the macro with
CALL SYMPUT,
Proc SQL ,
%LET assertion. And macro parameters.
Q13. Describe The Ways In Which You Can Create Macro Variables?
There are the 5 methods to create macro variables:
%Let
%Global
Call Symput
Proc SQl into clause
Macro Parameters.
Q14. What Is The Maximum Length Of The Macro Variable?
32 characters long.
Q15. What Are Symget And Symput?
SYMPUT puts the price from a dataset into a macro variable in which as SYMGET receives the value from the macro variable to the dataset.
Q16. How Would You Identify A Macro Variable?
With Ampersand (&) sign.
Q17. Can You Execute A Macro Within A Macro? Describe.
Yes, Such macros are known as nested macros. They may be acquired with the aid of the use of symget and call symput macros.
Q18. How Would You Invoke A Macro?
After I even have defined a macro I can invoke it via adding the percent sign prefix to its call like this: % macro call a semicolon isn't always required when invoking a macro, though adding one generally does no damage.
Q19. How Would You Define The End Of A Macro?
The cease of the macro is described via %Mend Statement.
Q20. How Do You Add A Number To A Macro Variable?
Using %eval feature or %sysevalf function if the variety is a floating quantity.
Q21. How Would You Code A Macro Statement To Produce Information On The Sas Log? This Statement Can Be Coded Anywhere?
OPTIONS MPRINT MLOGIC MERROR SYMBOLGEN.
Q22. If You Use A Symput In A Data Step, When And Where Can You Use The Macro Variable?
The macro variable created through the CALL SYMPUT habitual can't be used within the identical datastep in which it got created. Other than that we will use the macro variable at any time.
Q23. How Long Can A Macro Variable Be? A Token?
A factor of SAS known as the phrase scanner breaks the program textual content into essential gadgets called tokens.
Tokens are passed on demand to the compiler.
The compiler then requests token till it receives a semicolon.
Then the compiler performs the syntax test on the statement.
Q24. 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?
SAS Enables the consumer to name macros that have been stored as SAS programs.
The vehicle call macro facility allows customers to get right of entry to the same macro code from more than one SAS applications. Rather than having the same macro code for in every program where the code is needed, with an autocall macro, the code is in a single region. This lets in faster updates and higher consistency across all the programs.Macro set-up:The fist step is to set-up a application that incorporates a macro, preferred to be used in a couple of applications. Although the program may include different macros and/or open code, it's miles advised to encompass simplest one macro.
Set MAUTOSOURSE and SASAUTOS:
Before you'll use the autocall macro inside a SAS program, The MAUTOSOURSE choice have to be set open and the SASAUTOS alternative must be assigned. The MAUTOSOURSE alternative indicates to SAS that the autocall facility is to be activated. The SASAUTOS choice tells SAS wherein to look for the macros.
For ex: sasauto=’g:busmeasinternalmacro’.
Q25. What Do You Code To Create A Macro?
We create a macro with %MACRO assertion and end a macro with %MEND statemnt.

